Turn on WCF Tracing to Make Debugging & Troubleshooting Easier

network-3154910_1920Debugging an API or anything invoked on a remote machine can be a pain. You typically can't set break points and step through the code.

That is why detailed logs are valuable.

Tracing, another word for creating logs, can give you the run-time insight you need to troubleshoot problems.

Windows Communication Foundation (WCF) tracing is the way you create these logs from your API.

It is not enabled by default, so you must turn it on.

WCF tracing is 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:









































   

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 view-able 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.

Share This Article With Your Friends!

Googles Ads Facebook Pixel Bing Pixel LinkedIn Pixel