Friday, December 18, 2009

WCF Service Trace Viewer (SvcTraceViewer.exe) tool

image

If you're familiar with WCF application development, some times, you might across this kind of exception thrown back to client after unsuccessful service operation. Above exception in the screen shot doesn't provide any detailed information regarding the source of exception or any stack trace.

Windows Communication Foundation (WCF) Service Trace Viewer is a useful utility to help analyze WCF messages that are exchanged between service and client. Any inner exception buried deep in the stack trace can be traced, analyzed and diagnosed. Some times, due to security concerns, WCF services doesn't emit complete exception details back to the client. Lot of times, cryptic, brief and vague exceptions thrown by WCF service leaves no clue about the error. For example, lot of times you find "Connection closed abruptly/MessageSecurity exception/ Security token" exception being thrown back to WCF client.

Even if you turn on IncludeExceptionDetailInFaults service behavior element to True, Some times, you don't get the complete picture you expect. In such scenarios, Service Trace viewer tool is really helpful increasing productivity and saving time and takes us to the right spot of error occurence. We can utilize Service Trace Viewer Tool (SvcTraceViewer.exe) for WCF service level tracing and instrumentation.
We can configure tracing using either app.config file or web.config file. We can easily enable tracing/message logging using Service configuration Editor tool which can be accessed from Visual Studio IDE (Tools section of MainMenu).

Service Trace Viewer tool generates tracing file (.svcLog). This tool also supports two other file types
(Event Tracing file(.etl) and Crimson Tracing file

WCF service generates .svcLog files.


After enabling tracing/message logging in config files using WCF service configuration editor, exchange couple of messages between WCF service and client for recording trace. You can enable tracing/logging both at the client and service side in their respective config files.

image

image

To open a trace file, navigate to your WCF installation location (C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin), then you can find SvcTraceViewer.exe in bin folder or you can also access it from start menu as shown below.

image

After you open the service trace viewer tool, Now try to open your .svcLog file from the location you specified in the config file.

Service Trace Viewer supports four different views of trace data.
  • Activity view 
  • Project view 
  • Message view 
  • Graph view.
Below screenshot display default activity view from trace viewer. In Activity view, all the related traces are grouped into activities. The activity view displays activity names, number of traces and duration.

To view a trace detail, select a trace in the trace pane. The details are displayed in the Detail pane.
Detail pane which is located in bottom left provides three tabs to view trace details. Formatted view displays the information in a more organized way. You can see formatted view in the screenshot. XML View displays XML related to the trace. The Message view displays the message part of the XML in message log traces. It is invisible when you select a non-message trace.