Saturday, March 17, 2012

Logging SOAP messages for a WCF Web Service

I had a need to log inbound SOAP messages to a WCF Web Service. It turns out this is really easy to do by adding some entries in the web.config.  Please note this only works with WCF services, not the old style ASMX web services. 

As always take a backup of the web.config before making changes.

Find the </system.servicemodel>tag and then just above it add

<messagelogging logentiremessage="true" logmalformedmessages="false" logmessagesatservicelevel="true" logmessagesattransportlevel="false" maxmessagestolog="3000" maxsizeofmessagetolog="3000" />

Then at the bottom of the web.config just before </configuration>add this

<trace autoflush ="true" />
<source name="System.ServiceModel.MessageLogging">
<add initializedata="c:\PDFOutput\messages.svclog" name="messages" type="System.Diagnostics.XmlWriterTraceListener"/>

Be sure to use the svclog extension.  Recycle your WCF service and send some messages through. 
Now you are going to find the svclog hard to read unless you have the SVCTraceViewer.EXE 
Its part of the Windows SDK and well worth downloading.

No comments: