Saturday, April 12, 2008

Debugging WCF Applications - 2 Ways to do it!

At some point if you are a WCF developer, you will realize the pain of developing and Debugging web services and it's not a question of if you will encounter the dreaded "The Underlying Connection Closed unexpectedly" error, it's just a question of when. If you are doing a lot of object serialization (like trying to bring back an ArrayList) you will encounter this error very quickly. This post will help to solve "The Underlying Connection Closed unexpectedly" by enabling you to debug your WCF Projects properly.

There are really 2 ways to debug WCF Projects. 

The first and not so obvious but simple way, which will only get you so far, is to set break points in your WCF project and then run the project in the visual studio debugger. Then from your project that your are calling the service reference from, be sure to add the debugger url as your service reference and then run the program. (Usually your debugging web service if you open up visual studio will be http://localhost:{some port}/YourService.svc )

Depending on which service you are hitting, you can step through the break points. For simple debugging and simple errors, this method work very quickly.

You will find out very quickly though that this way will not catch all your errors. 

 The documentation on Debugging WCF is very sparse and not intuitive, and for the documentation that is available, it is somewhat long winded, so I will just get to the point:

Therefore, you must master the use of configuring your web.config files, use the tool.

"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\SvcConfigEditor.exe"

To create your configuration files. You will use this tool to modify your web.config file to enable the Message tracing and service tracing.

Once this is done, after you run your program if it craps out, you then use the

"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\SvcTraceViewer.exe"

to view your trace files. It is from within this trace log file you will be able to find out what went wrong in your WCF File.

That's all there is to WCF Debugging!

A Good Link on CodeProject

No comments: