Debugging Web Service calls and Soap Messages

The Muhimbi Conversion Service is a Windows Service based on the Microsoft Windows Communication Foundation (WCF) framework. This comprehensive framework is used to expose a standards based Web Services interface that can be consumed by many different platforms including .NET, Java, PHP, SAP, Documentum and many others.

Even though WCF Web Services are standards based, standards are not interpreted the same by everyone so from time to time you may need to do some troubleshooting when programming against  the Document Converter Web Service, especially from non-Microsoft platforms.

Fortunately WCF comes with extensive tracing and logging facilities that can be used to log exactly what is going on during a Web Service call, including the logging of SOAP messages, which is particularly useful.

You can enable WCF logging as follows. Please revert  these settings when you are done as the log files will grow very quickly.

  1. Open the Conversion Service’s config file in notepad. It is located in the folder the software has been deployed to, there is a handy shortcut to this folder in the Windows Start menu. The config file is named ‘Muhimbi.DocumentConverter.Service.exe.config’.

  2. Just before the ‘’ element add the following. Update the location of the log file (in red) if needed:

  3. <system.diagnostics>
     <sources>
      <source name="System.IdentityModel"
              switchValue="Verbose"
              logKnownPii="true">
       <listeners>
        <add name="xml" />
       </listeners>
      </source>
      <!-- Log all messages in the 'Messages' tab of SvcTraceViewer. -->
      <source name="System.ServiceModel.MessageLogging">
       <listeners>
        <add name="xml" />
       </listeners>
      </source>
      <!-- ActivityTracing and propogateActivity are used to flesh out the
           'Activities' tab in SvcTraceViewer to aid debugging. -->
      <source name="System.ServiceModel"
              switchValue="Error, ActivityTracing"
              propagateActivity="true">
       <listeners>
        <add name="xml" />
       </listeners>
      </source>
      <!-- This records Microsoft.IdentityModel generated traces, including
           exceptions thrown from the framework. -->
      <source name="Microsoft.IdentityModel" switchValue="Warning">
       <listeners>
        <add name="xml" />
       </listeners>
      </source>
     </sources>
     <sharedListeners>
      <add name="xml"
           type="System.Diagnostics.XmlWriterTraceListener"
           initializeData="C:\trace.svclog" />
     </sharedListeners>
     <trace autoflush="true" />
    </system.diagnostics>
  4. In the ‘<system.serviceModel>’ element add the following:

  5. <diagnostics>
     <!-- log all messages sent/received at the transport/service model level -->
     <messageLogging logEntireMessage="true"
                     maxMessagesToLog="1000"
                     maxSizeOfMessageToLog="69905067"
                     logMessagesAtServiceLevel="true"
                     logMalformedMessages="true"
                     logMessagesAtTransportLevel="true" />
    </diagnostics>
  6. Save the config file and restart the Muhimbi Document Converter Service.

  7. Make a single Web Service call to log all information to the Trace Log. You may want to log the same operation using the Diagnostics Tool that ships with our Document Converter, also available in the Windows Start menu. You can then verify the SOAP message logged by your software with the message logged by our software.

  8. Open the log file (C:\trace.svclog) in SvcTraceViewer.exe. If already installed on your system then double clicking the log file should open it. If the viewer is not installed then download the Windows SDK (You only need to install .NET Development / Tools).

  9. In the Trace Viewer navigate to the first ’ Process action…’ activity and select the Message Log Trace option followed by the Message tab. Alternatively click on the top level Message tab to display all messages. (Switch to the ‘Message View’ by subsequently clicking the Message tab in the bottom-right pane).

If the difference between your request and the request made by the Muhimbi Diagnostics tool is not immediately clear then you can use a free ‘Diff’ tool to compare two Soap Messages (not the entire trace file) and highlight the differences. Depending on your Web Services framework you may want to rename the namespaces in one of the messages so it matches the other’s as this reduces the number of differences highlighted.(e.g. replace all “<ns1:” & “</ns1:” references with “<a:” & “</a:”).

For more details about WCF logging see the MSDN Website.