How to trace WCF serialization issues / exceptions
Asked Answered
G

2

10

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 : 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.

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?

thank you

Glaucoma answered 6/5, 2010 at 8:55 Comment(0)
B
6

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

Bacardi answered 6/5, 2010 at 10:39 Comment(2)
thanks for your reply. The includeExceptionDetailInFaults attribute only applies for exceptions that occur inside your OperationContract boundaries. issues during serialization occur outside these boundaries. Your second proposal might be a solution to log (but not handle) these issues. I will take a deeper look it.Glaucoma
Many thanks for the link. Logging helped me to find the problem.Aspirator
G
0

I had that problem, and it was a serialization issue... sometimes I was sending a DataTable without any column, in that case the channel just closed without any error or trace.

Gargoyle answered 15/9, 2010 at 20:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.