如何跟踪WCF序列化问题/异常异常、序列化、问题、WCF

2023-09-03 03:32:00 作者:7.樱桃肉肉丸

我偶尔会碰到一个应用程序异常的WCF序列化过程中引发的(从我的OperationContract的返回DataContract后)的问题。唯一的(少meaningfull)消息我得到的是

I occasionally run into the problem that an application exception is thrown during the WCF-serialization (after returning a DataContract from my OperationContract). The only (and less meaningfull) message I get is

System.ServiceModel.CommunicationException   :基础连接是   关闭:连接被关闭   出乎意料的。

System.ServiceModel.CommunicationException : The underlying connection was closed: The connection was closed unexpectedly.

没有任何了解的内部异常,这使得它真的很难找出序列化过程中造成的错误。

without any insight to the inner exception, which makes it really hard to find out what caused the error during serialization.

是否有人知道一个很好的方法,你如何跟踪,记录和调试这些异常?甚至更好,我可以捕获异常,处理它们并发送一个定义FaulMessage到客户端?

Does someone know a good way how you can trace, log and debug these exceptions? Or even better can I catch the exception, handle them and send a defined FaulMessage to the client?

谢谢

推荐答案

您应该如果配置这样您的服务行为得到内部异常:

You should get the inner exception if you configure your service behavior like this:

<system.serviceModel>
     <behaviors>
         <serviceBehaviors>
               <behavior name="YourServiceBehaviour">
                   ...
                   <serviceDebug includeExceptionDetailInFaults="true" />
                   ...
               </behavior>
         </serviceBehaviors>
     </behaviors>
</system.serviceModel>

此外,您可以启用跟踪。没有找到好的文章了,但也许这可以让你开始:

Additionally you can enable tracing. Did not find a good article now, but maybe this gets you started:

http://developers.de/blogs/damir_dobric/archive/2009/03/24/using-of-wcf-trace.aspx