Skip to content

View Contents of HTTP WCF Message with Message Logging & Service Trace Viewer

If you would like to see the contents of your WCF message body packet as understood by the server, you can enable WCF message logging via a few adjustments in your WCF Service Web.config file and by then by using the Microsoft Service Trace Viewer application to view it.

I found best results by creating a directory on your system drive, C:\logs\ and storing your WCF messages in there. Everytime I specified the .svclog file to be in the same directory as where my app was, it wasn’t being created, but that could just be my local system permissions at play.

So all you need to do to enable this is in the Web.config of your WCF Service (Host):

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelMessageLoggingListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="c:\logs\web_messages.svclog" type="System.Diagnostics.XmlWriterTraceListener"
       name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>

  <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true" logMalformedMessages="true"
       logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
       maxSizeOfMessageToLog="2147483647" />
    </diagnostics>

Then run the client app and perform your WCF call, a new web_messages.svclog file should have been created which can now be opened and viewed.

The most interesting data will be under the XML and Messages tabs once you have clicked a message to view.

The default view is not bad, but by pressing ALT-3 within the trace viewer application you will enter message view which I feel is better suited for messaging viewing (how profound).

<system.diagnostics>
<sources>
<source name=”System.ServiceModel.MessageLogging” switchValue=”Warning, ActivityTracing”>
<listeners>
<add type=”System.Diagnostics.DefaultTraceListener” name=”Default”>
<filter type=”" />
</add>
<add name=”ServiceModelMessageLoggingListener”>
<filter type=”" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData=”c:\logs\web_messages.svclog” type=”System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″
name=”ServiceModelMessageLoggingListener” traceOutputOptions=”Timestamp”>
<filter type=”" />
</add>
</sharedListeners>
<trace autoflush=”true” />
</system.diagnostics>

<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage=”true” logMalformedMessages=”true”
logMessagesAtServiceLevel=”true” logMessagesAtTransportLevel=”true”
maxSizeOfMessageToLog=”2147483647″ />
</diagnostics>

VN:F [1.9.1_1087]
Rating: 3.0/5 (1 vote cast)
VN:F [1.9.1_1087]
Rating: +1 (from 1 vote)
View Contents of HTTP WCF Message with Message Logging & Service Trace Viewer, 3.0 out of 5 based on 1 rating
Bookmark and Share
kick it on DotNetKicks.com
Shout it

NOW, FOR A WORD FROM OUR SPONSORS

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*
My name is Graham O'Neale and I'm a software architect from Gold Coast, Australia. I am an overtime thinker, full time coder and awake part time in the real world. I have a keen interest in software development, particularly in the realm of programming (C#, ASP.NET, ASP.NET MVC, LINQ (2 SQL), Entity Framework, Silverlight, Blend, WCF, WPF) and a keen interest in the cutting edge and innovation. I have a new found love for design patterns, ALT.NET practices and well crafted software architecture. The purpose of this blog is to express any thoughts, findings, tips and gripes along my travels in the wonderful world of coding and technology...