如何调试 WebServiceHost 中的序列化错误?
我有一个自托管的 WebServiceHost
定义如下:
var baseWebHttpBindingBase = "http://localhost:8085/MyService");
var wsEndPoint = new EndpointAddress(baseWebHttpBindingBase);
var binding = new WebHttpBinding();
wsHost = new WebServiceHost(lsWsService, new Uri(baseWebHttpBindingBase));
wsHost.Faulted += new EventHandler(wsHost_Faulted);
wsHost.UnknownMessageReceived += new EventHandler<UnknownMessageReceivedEventArgs>(wsHost_UnknownMessageReceived);
ServiceDebugBehavior sdb = host.Description.Behaviors.Find<ServiceDebugBehavior>();
sdb.IncludeExceptionDetailInFaults = true;
// Mex endpoint
ServiceMetadataBehavior mexBehavior = new ServiceMetadataBehavior();
mexBehavior.HttpGetEnabled = true;
wsHost.Description.Behaviors.Add(mexBehavior);
wsHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), baseWebHttpBindingBase + "mex");
wsHost.Open();
我有一个 OperationContract
定义:
[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, Method = "PUT", UriTemplate = "/handShake")]
public ConfigSettings handShake(ClientInformationDto clientInfo) {
var configSettings = new ConfigSettings();
// set configSettings values;
return configSettings;
}
ConfigSettings 有一些杂项。属性,主要定义为字符串和整数。不过,有一个名为 List
类型的complexClasses 属性 - 如果complexClasses 为null,则客户端可以正常使用Web 服务。但是,如果我填充complexClasses,则使用Web服务的尝试永远不会完成 - 在Fiddler中观看它只会显示通用的ReadResponse()失败:服务器没有返回此请求的响应。
当我调试时代码中,我到达 return 语句,当我执行最后一步时,Fiddler 报告上述错误。
我知道问题与 configSettings 中的 ComplexClass 有关。该服务继续运行得很好,甚至在启用 Studio 的“中断所有异常”功能后也不会出现任何中断。无论如何,是否可以调试返回后发生的任何情况(最有可能在序列化阶段)导致我的服务无法返回任何内容?
I've got a self-hosted WebServiceHost
defined like so:
var baseWebHttpBindingBase = "http://localhost:8085/MyService");
var wsEndPoint = new EndpointAddress(baseWebHttpBindingBase);
var binding = new WebHttpBinding();
wsHost = new WebServiceHost(lsWsService, new Uri(baseWebHttpBindingBase));
wsHost.Faulted += new EventHandler(wsHost_Faulted);
wsHost.UnknownMessageReceived += new EventHandler<UnknownMessageReceivedEventArgs>(wsHost_UnknownMessageReceived);
ServiceDebugBehavior sdb = host.Description.Behaviors.Find<ServiceDebugBehavior>();
sdb.IncludeExceptionDetailInFaults = true;
// Mex endpoint
ServiceMetadataBehavior mexBehavior = new ServiceMetadataBehavior();
mexBehavior.HttpGetEnabled = true;
wsHost.Description.Behaviors.Add(mexBehavior);
wsHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), baseWebHttpBindingBase + "mex");
wsHost.Open();
I've got an OperationContract
defined:
[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, Method = "PUT", UriTemplate = "/handShake")]
public ConfigSettings handShake(ClientInformationDto clientInfo) {
var configSettings = new ConfigSettings();
// set configSettings values;
return configSettings;
}
ConfigSettings has some misc. properties, mostly defined as strings and ints. There's one property though that is named complexClasses of type List<ComplexClass>
- if complexClasses is null, then the client can consume the webservice just fine. However, if I populate complexClasses, the attempt to consume the webservice never completes - watching it in Fiddler just shows a generic ReadResponse() failed: The server did not return a response for this request.
When I debug the code, I get to the return statement and when I do the final step out, Fiddler reports to above error.
I know the problem is related to my ComplexClass in configSettings. The service continues to run just fine, and even after enabling Studio's "break on all exceptions" feature nothing ever breaks. Is there anyway to debug whatever happens after returning (most likely in the serialization stage) that is causing my service to fail to return anything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ComplexClass 可能未正确序列化。 ComplexClass 需要使用序列化属性来公开。
It is possible that ComplexClass is not serialized properly. ComplexClass needs to be exposed with Serialization attributes.