How to debug WCF service server side errors

So, here is the issue I encountered today.  I have a solution that is using WCF service to communicate.  My WCF service is hosted in a web site (web application project).  I was getting error from my client, stating that connection was forcibly closed by the server.  I could not figure out why even though I configured behavior to "includeExceptionDetailInFaults".  So, here is the solution that I found.

I added the following to web.config file to web site that hosts WCF service.

<system.diagnostics>
        <sources>
            <source name="System.ServiceModel"
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
                <listeners>
                    <add name="traceListener"
                        type="System.Diagnostics.XmlWriterTraceListener"
                        initializeData= "c:Traces.svclog" />
                </listeners>
            </source>
        </sources>
    </system.diagnostics>

Voila.  I ran the process again, double-clicked on trace log that opened in a viewer.  I was informed that I forgot to add Serializable attribute to my class I was sending across the wire.

What an easy solution!  What a greate WCF feature as well – you can debug service even in production without changing code – just change configuration file.  The same trick works in Windows hosted WCF services – just add the same stuff to app.config.

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *