Sunday, April 21, 2013

Finding the Root Cause of WCF Exceptions

When setting up a WCF service, calls can fail for many reasons. The frustrating part is that we typically get a generic error:

The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.8380000'.

In order to find out exactly what was wrong, simply configure tracing, by placing this in the config file of the WCF service:


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

Note: The above configuration is from http://msdn.microsoft.com/en-us/library/ms733025.aspx.

After trying the WCF call again, open Traces.svclog and find the activity in red:


After clicking on the activity, click on the description/error in the right window pane:


The bottom pane will show you exactly what's wrong:



No comments: