Tracing SOAP Messages in WCF

Saturday, August 2, 2008

This is a nice feature that comes with WCF (Windows Communication Foundation) with regards to debugging SOAP messages.  With VS 2005, out of the box there is no way to trace message when your message is not well formed and cannot be parsed.  You have to download WSE 3 or another third party tool like Contract First to assist in debugging.

 

WCF in VS 2008 comes with a neat tool out of the box called SvcTraceViewer.exe.  To use it, you configure your service to log events when a message is made.  To do that you use the following configuration:

 

<system.serviceModel>
    <!-- add trace logging -->
    <diagnostics wmiProviderEnabled="true">
      <messageLogging
           logEntireMessage="true"
           logMalformedMessages="true"
           logMessagesAtServiceLevel="true"
           logMessagesAtTransportLevel="true"
           maxMessagesToLog="3000"
       />

    </diagnostics>     
  </system.serviceModel>
  <!-- define trace logging -->
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true" >
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml"
           type="System.Diagnostics.XmlWriterTraceListener"
           initializeData="C:\logs\CommandLineSTS.svclog" />
    </sharedListeners>

  </system.diagnostics>

 

Once your service is configured to log messages you can then use the tool to see the SOAP message and whatever exception were captured.  Below is a sample SOAP call to the QuickSell message logged.

  

 

comments powered by Disqus