Where's the SOAP?

WCF provides an abstraction for web services, which while convenient to code against can be difficult to debug – particularly when you want to see the SOAP messages being sent back and forth.

In order to see your Requests and Responses you need to enable tracing in your application’s config file, like so:

<system.serviceModel>
  <diagnostics>
    <messageLogging logEntireMessage="true" 
                    logMalformedMessages="true" 
                    logMessagesAtServiceLevel="true" 
                    logMessagesAtTransportLevel="true" 
                    maxMessagesToLog="500"/>
  </diagnostics>
  …
</system.serviceModel>
<system.diagnostics>
  <sources>
    <source name="System.ServiceModel" 
            switchValue="All" 
            propagateActivity="true">
      <listeners>
        <add name="traceListener" />
      </listeners>
    </source>
    <source name="System.ServiceModel.MessageLogging" 
            switchValue="All">
      <listeners>
        <add name="traceListener" />
      </listeners>
    </source>
  </sources>
  <sharedListeners>
    <add name="traceListener" 
          type="System.Diagnostics.XmlWriterTraceListener" 
          initializeData="c:\Traces.svclog" />
  </sharedListeners>
  <trace autoflush="true"/>
</system.diagnostics>

This will save a Traces.svclog to your C drive, which when double-clicked opens up in Microsoft Service Trace Viewer.

If you look through the log for Message Log Trace entries you will see the SOAP Request and Response messages in the XML tab:

Microsoft Service Trace Viewer

Comments