Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider Follow Me On Twitter
Turn on WCF Tracing for WCF Troubleshooting

Yesterday I posted an entry on dealing with larger result sets that cause Fidder to create a ReadResponse() failed error. In that post I mentioned I turned on WCF Tracing to help debug the problem. This is a setting that when turned on causes the WCF stack to generate a couple of log files that can be used to see the details of what is going on. You can read more about the details of WCF Tracing on the MSDN site.

To turn on WCF tracing you need to add some sections to the web.config or app.config of your application:

<?xml version="1.0" encoding="utf-8"?>

<configuration>

<system.diagnostics>

<sources>

<source name="System.ServiceModel"
switchValue="Error,ActivityTracing"

propagateActivity="true">

<listeners>

<add type="System.Diagnostics.DefaultTraceListener"
name="Default">

<filter type="" />

</add>

<add name="ServiceModelTraceListener">

<filter type="" />

</add>

</listeners>

</source>

<source name="System.ServiceModel.MessageLogging"
switchValue="Warning, ActivityTracing">

<listeners>

<add type="System.Diagnostics.DefaultTraceListener" name="Default">

<filter type="" />

</add>

<add name="ServiceModelMessageLoggingListener">

<filter type="" />

</add>

</listeners>

</source>

</sources>

<sharedListeners>

<add initializeData="tracelog.svclog"

type="System.Diagnostics.XmlWriterTraceListener, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"


name="ServiceModelTraceListener" traceOutputOptions="Timestamp">

<filter type="" />

</add>

<add initializeData="messages.svclog"

type="System.Diagnostics.XmlWriterTraceListener,
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"


name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">

<filter type="" />

</add>

</sharedListeners>

<trace autoflush="true" />

</system.diagnostics>

<system.serviceModel>

<diagnostics>

<messageLogging logMalformedMessages="true"
logMessagesAtServiceLevel="true"

logMessagesAtTransportLevel="true" />

</diagnostics>

</system.serviceModel>

</configuration>

If you already have a serviceModel section you can just add the existing diagnostics section. Once you have these configuration sections in place WCF will start tracing all calls.

The tracing infrastructure creates two trace files. These files can be viewed using the Microsoft Service Trace Viewer.

WCF Trace Viewer

The Service Trace Viewer breaks the trace report into a viewable representation of the data and much like fiddler gives you the ability to view the data in the raw XML format. If you notice at the bottom of the view (click the image to enlarge it to full screen) you will see the following error message.

There was an error while trying to serialize parameter urn:
[ProjectNameSpace].UI.WebSite.WebServices.ServiceContracts.[ServiceName]:FindOrdersResult.
The InnerException message was 'Maximum number of items that can be serialized or deserialized
in an object graph is '
65536'. Change the object graph or increase the MaxItemsInObjectGraph quota. '.
Please see InnerException for more details.

Service namespace obfuscation aside this tells me what the real issue with my service call is. In this case the result set is larger than the default allowed. It also tells me I what I need to do, increase the MaxItemsInObjectGraph property. This allowed me to concretely make decisions to solve my problem.

So just like you can inject detail error error logging in the ASP.NET pipeline, like ELMAH, you have a built in tracing and logging solution that comes with WCF.

Posted: Thursday, September 02, 2010 9:06 AM

by Chris Love
Filed under: , ,

Comments

Ali said:

Thank you for this great article. It helped me a lot.
# September 2, 2010 11:16 AM

Peter Kellner said:

Book Marked! Thanks for posting. I always forget how to do this and have been meaning to write myself a blog post so I will remember. Now, I don't have to. Nice job. See you at PDC?
# September 3, 2010 12:01 PM

Steve S. said:

You have a common mistake, which is the specification of a switchValue for the System.ServiceModel.MessageLogging. From: http://msdn.microsoft.com/en-us/library/ms730064.aspx "The switchValue attribute of a source is only valid for tracing. If you specify a switchValue attribute for the System.ServiceModel.MessageLogging trace source as follows, it has no effect." and.... "If you want to disable the trace source, you should use the logMessagesAtServiceLevel, logMalformedMessages, and logMessagesAtTransportLevel attributes of the messageLogging element instead. You should set all these attributes to false." HTH
# September 17, 2010 10:07 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS