Wednesday, November 26, 2008

WCF Tracing with SvcTraceViewer

I had a problem with an WCF Service that I'd written that was reading from an MSMQ and would blow up if the message was larger than 64K. Once I'd tracked down the exception that was being thrown (QuotaExceededException) a quick search on Google with "wcf quotaexceededexception" landed me on Hugo Batista's blog site and his WCF: maxReceivedMessageSize and QuotaExceededException post which was exactly what I was experiencing and this solved the problem.

This, however, did not solve the problem of how incredibly difficult I found it to log that QuotaExceededException exception. Like Hugo Batista I'd tried to catch the UnhandledException event from the AppDomain but this was unsuccessful.

Eventually I discovered that I could turn on Message Logging and Tracing in the App.config file and then use the SvcTraceViewer application to look at those files. This worked a charm and the tools make it pretty easy.

First you need to edit the App.config file but Visual Studio 2008 has a utility that makes this very easy for WCF. Right click on the App.config file and you will see an option "Edit WCF Configuration." This brings up the Microsoft Service Configuration Editor which makes editing this much easier. In the Configuration section on the left hand side click on Diagnostics and then click on the links "Enable MessageLogging" and "Enable Tracing" and set the locations for the log files.

Now run the errant web service and once it's faulted the channel open the error file with SvcTraceViewer. I found SvcTraceViewer in the "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\" folder on my XP machine. The tracelog is where you'll find the warnings etc.

No comments:

Post a Comment