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:

System.Diagnostics.Debugger.Break();

 

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

image

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!

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: