This is more of a reminder post rather than a tutorial/howto.
In the pre-WCF era, in order to be able log/audit the raw requests and responses sent to a web service, you'd have to create a SoapExtension. In the "modern" era, however, things function slightly differently. You can use diagnostics tracing to log (much more than) these service messages. Recommended settings here.
Just make sure you have BOTH parts included:
<system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="Warning" propagateActivity="true" > <listeners> <add name="xml"/> </listeners> </source> <source name="myUserTraceSource" switchValue="Warning, ActivityTracing"> <listeners> <add name="xml"/> </listeners> </source> </sources> <sharedListeners> <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\logs\Traces.svclog" /> </sharedListeners> </system.diagnostics>
<system.serviceModel> <diagnostics> <messageLogging logEntireMessage="true" logMalformedMessages="false" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="false" maxMessagesToLog="3000" maxSizeOfMessageToLog="2000"/> </diagnostics> </system.serviceModel>
The first part instructs the application what to listen for and where/how to record the data, while the latter part tells the application what to actually include in the log. Omitting the second part, will not result in an error. It will only result in a very baffled developer, as the application will not log anything at all and not produce even a warning as to what is wrong.