The Service Trace Viewer provides a way of viewing the activity of WCF hosts and clients. This utility is available in the Windows SDK for Framework 3.0.
If you are not familiar with the SvcTraceViewer application, then the following is an example of using the tool when viewing tracing of the Simple Header Example created in an earlier post.
To enable tracing of a WCF service or client, you can use the following settings in the service model section of configuration shown below:
1: <system.serviceModel>
2: ...
3: <diagnostics>
4: <messageLogging maxMessagesToLog="100"
5: logEntireMessage="true"
6: logMessagesAtServiceLevel="true"
7: logMalformedMessages="true"
8: logMessagesAtTransportLevel="true">
9: </messageLogging>
10: </diagnostics>
11: </system.serviceModel>
Note: in the above example, I have the maxMessagesToLog set to 100. This limits the size of the trace file to only 100 messages. Once this limit is met, no more messages will be added to the trace log until it is cleared of previous messages.
And to capture the trace events you can use a trace listener. The following configuration settings illustrates using the XmlWriterTraceListener in the System.Diagnostics library to capture the trace events from both the System.ServiceModel and the System.ServiceModel.MessageLogging namespaces:
1: <system.diagnostics>
2: <sources>
3: <source name="System.ServiceModel"
4: switchValue="Information, ActivityTracing"
5: propagateActivity="true">
6: <listeners>
7: <add name="xml" />
8: </listeners>
9: </source>
10: <source name="System.ServiceModel.MessageLogging"
11: switchValue="Information">
12: <listeners>
13: <add name="xml" />
14: </listeners>
15: </source>
16: </sources>
17: <sharedListeners>
18: <add name="xml"
19: type="System.Diagnostics.XmlWriterTraceListener"
20: initializeData="Traces.svclog" />
21: </sharedListeners>
22: <trace autoflush="true" />
23: </system.diagnostics>
In the Simple Header Example, I added the above configuration settings to all three projects (WCFClient1, WCFClient2, and WCFHost). After running the example, a Traces.svclog file was created in each of the execution folders.
If you were to open the log file created in the host folder, you should see something similar to:
Please see the documentation online regarding the Service Trace Viewer as it is good. Just to mention a couple of things in regards to the handling of the WCF incoming headers created in the WCF Simple Header Example.

If you select the Messages tab, you will see a list of the messages exchanged between the host and the clients. Note, the example to the right shows a message received from the WCFClient2 for GetMembership("Henry") call.
In the header example, the SOAP headers can be viewed in detail by selecting the XML table in the lower right pane. The snippet below shows the header received from the WCF Client 2 where the message is sent as a simple string:
1: <E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
2: <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
3: ...
4: </System>
5: <ApplicationData>
6: <TraceData>
7: <DataItem>
8: <MessageLogTraceRecord Time="2007-08-06T08:33:33.4370353+12:00" Source="ServiceLevelReceiveRequest" Type="System.ServiceModel.Channels.BufferedMessage" xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
9: <HttpRequest>
10: ...
11: </HttpRequest>
12: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
13: <s:Header>
14: <SourceApplication xmlns="urn:spike.WCFHeaderExample:v1">WCFClient Application 2</SourceApplication>
15: ...
16: </s:Header>
17: <s:Body>
18: <GetMembership xmlns="http://tempuri.org/">
19: <name>Henry</name>
20: </GetMembership>
21: </s:Body>
22: </s:Envelope>
23: </MessageLogTraceRecord>
24: </DataItem>
25: </TraceData>
26: </ApplicationData>
27: </E2ETraceEvent>
The following snippet shows the header sent as an object:
1: <E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
2: <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
3: ...
4: </System>
5: <ApplicationData>
6: <TraceData>
7: <DataItem>
8: <MessageLogTraceRecord Time="2007-08-06T08:33:33.3587178+12:00" Source="TransportReceive" Type="System.ServiceModel.Channels.BufferedMessage" xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
9: <HttpRequest>
10: ...
11: </HttpRequest>
12: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
13: <s:Header>
14: <ServiceContext xmlns="urn:spike.WCFHeaderExample:v1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
15: <SourceApplication>WCFClient Application 1</SourceApplication>
16: </ServiceContext>
17: ...
18: </s:Header>
19: <s:Body>
20: <GetMembership xmlns="http://tempuri.org/">
21: <name>Jim</name>
22: </GetMembership>
23: </s:Body>
24: </s:Envelope>
25: </MessageLogTraceRecord>
26: </DataItem>
27: </TraceData>
28: </ApplicationData>
29: </E2ETraceEvent>
Posted
Tue, Aug 7 2007 5:30 PM
by
chilberto