WCF Debugging

October 23, 2015

WCF is a good product in so many respects; but error reporting isn’t one of them. Whilst trying to get a WCF service to work, I encountered this error:

Exception thrown: ‘System.ServiceModel.CommunicationException’ in mscorlib.dll

Additional information: An error occurred while receiving the HTTP response to http://localhost:17065/Service1.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

WCFError

Diagnosis

The following will produce a surprisingly useful diagnosis file.

To add diagnostics, edit the web.config of the service and add:

<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Warning" propagateActivity="true">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>

      <source name="TraceSource" switchValue="Warning, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>      

    </sources>
    <sharedListeners>
      <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\\trc.svclog"/>
    </sharedListeners>
  </system.diagnostics>

And then:

  <system.serviceModel>
    <diagnostics wmiProviderEnabled="true">
      
    </diagnostics>


Now replicate the error and have a look in the directory you pointed the initializeData to (in my case c:\trc.svclog). Providing you’ve used the correct extension, double clicking the file should give you something like this:

WCFTrace



Profile picture

A blog about one man's journey through code… and some pictures of the Peak District
Twitter

© Paul Michaels 2024