LP on .NET

July 29, 2011

Debugging WCF Services in IIS

Filed under: C#,WCF — Larry Parker @ 3:43 pm

Until recently I’ve always self-hosted my WCF services in console apps during the development cycle, and in Windows services for production deployments.  Debugging my WCF services has always been very easy, especially when hosting in a console app.  I would simply run my console app solution from Visual Studio in debugging mode (by pressing F5), set a breakpoint in the WCF service code, have my client app hit the service, and the breakpoint would be hit in the debugger.

For my current project, I’m hosting WCF inside of IIS and could not easily debug my WCF services.  Even if I started up my web site from Visual Studio with F5 and set a breakpoint, it would not get hit when my client called the service.

As a crude workaround, I inserted the following line of code in my WCF service code:



Now when my client called the service I would get the following dialog box:


This approach allowed me to debug my WCF service code, but it was annoying since I had to modify my source code to insert the Debugger.Break() code, and then respond to a dialog box.

The solution to all of this is to simply run your web site and then attach Visual Studio to the aspnet_wp.exe process (mentioned in the above dialog box).  To do this, bring up Visual Studio’s Debug menu, select “Attach to Process…”, and then double click on aspnet_wp.exe in the list of available processes.

Now when your client hits your WCF service, your breakpoint will be hit in Visual Studio and you can debug your service code as expected, without having to insert Debugger.Break().

Hope this helps!


WCF Test Client

Filed under: C#,WCF — Larry Parker @ 3:14 pm

An invaluable tool I’ve been using quite a bit lately is the Windows Communication Foundation (WCF) Test Client.  You can find out more about it here on MSDN, but it’s basically a tool that acts as a service client by consuming an existing service and letting you interact with it through a nice user interface.

The program is named WcfTestClient.exe and can be found on your development machine in the following locations, depending on which version of Visual Studio you have installed:

Visual Studio 2008 C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE
Visual Studio 2010 C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE

Here’s a screenshot of the WCF Test Client working with a service that performs temperature conversion:


Notice how the tool dynamically creates types based on the service’s WSDL, lets you enter values for the request message properties, and displays the response message properties after you call the service (by clicking the Invoke button).

The XML tab at the bottom of the screen can also be used to inspect the exact request and response SOAP messages:


This is especially useful for debugging your service calls (e.g. to ensure the expected message namespace is being used).

Hope this helps.

July 25, 2011

Useful Visual Studio Shortcut Keys

Filed under: .NET,Visual Studio — Larry Parker @ 3:26 pm

Here’s a link to some useful Visual Studio shortcut keys:


Create a free website or blog at WordPress.com.