Message Logging and Tracing in Indigo
I really wanted to show how cool Indigo Windows Commuication Foundation is, not only by showing demos that use various bindings on the fly, but also to show what the messages look like on the wire. When I tried to use MSSoapT or TcpTrace, I got framing errors and couldn't show a trace with a completed service call. SvcTraceViewer is a great utility that ships with WCF that allows you to trace at various levels, including message logging.
I am currently using the PDC build for my demos (which allows me to show lots of cool stuff in Indigo that customers can currently replicate on their machines). The problem was that I could not get message logging to work, and I was too busy doing customer demos to really chase it down properly.
If you look at the documentation for the messageLogging element, it indicates that you should use the type System.ServiceModel.Diagnostics.MessageWriterTraceListener, which doesn't exist in the System.ServiceModel assembly. You can use the System.Diagnostics.XmlWriterTraceListener instead as the source. Make sure you specify a file name instead of a directory name.
Here is an example using a config file for the service project in the Net Profile: TCP sample. I bolded the relevant sections to update to get message level tracing to work with the PDC bits.
<? xml version="1.0" encoding="utf-8" ?>
< configuration xmlns="https://schemas.microsoft.com/.NetConfiguration/v2.0">
< appSettings>
<!-- use appSetting to configure base address provided by host -->
< add key="baseAddress" value="https://localhost:8000/servicemodelsamples/service" />
</ appSettings>
< system.serviceModel>
< services>
< service type="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior">
<!-- use base address provided by host -->
< endpoint address="net.tcp://localhost:9000/servicemodelsamples/service" binding="netTcpBinding" bindingConfiguration="Binding1" contract="Microsoft.ServiceModel.Samples.ICalculator" />
</ service>
</ services>
< bindings>
< netTcpBinding>
< binding configurationName="Binding1" hostNameComparisonMode="StrongWildcard" maxMessageSize="65536" maxBufferSize="65536" maxConnections="10" portSharingEnabled="false">
< reliableSession enabled="false" ordered="true"/>
< security mode="Transport" >
< transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"/>
</ security>
</ binding>
</ netTcpBinding>
</ bindings>
< behaviors>
< behavior configurationName="CalculatorServiceBehavior" returnUnknownExceptionsAsFaults="true" >
</ behavior>
</ behaviors>
< diagnostics >
< messageLogginglogMessagesAtTransportLevel="true" logEntireMessage="true" logMessagesAtServiceLevel="false"
/>
</ diagnostics >
</ system.serviceModel>
< system.diagnostics >
< sources >
< sourcename="IndigoMessageLogTraceSource"switchValue="Verbose" >
< listeners >
< addname="multifile" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:/logs/log.xml" />
</ listeners >
</ source >
</ sources >
</ system.diagnostics >
</ configuration>
Run the sample, and the log.xml file will show up in the c:/logs directory. After you have the logs available, you can use SvcTraceViewer to view the messages. Click the "Message" tab at the bottom left of the utility, and then choose the Formatted, XML, or Message view. The Message view is really cool as it gives a tabular view of the message (great for demos!) Here is the message view for the response message when the Add service method is called:
[SOAP Message Header]
|
[SOAP Body]
|