tags:

views:

348

answers:

2

I have a WCF test service and a test client in the same solution. The service is configured to run on localhost (Ie, "http://localhost:8731/Design_Time_Addresses/MyService/Service") I run the client app and it correctly invokes the service and gets back the correct answer. I've verified via logs that it's definitely running the service that's local to my machine. However, I can't debug into the service when running the client. WCF is supposed to allow just stepping through, but no breakpoints on the service get hit, and stepping in to the service call doesn't work either. Has anyone ever seen this?

I've checked all the obvious stuff like "is the PDB file being generated?" -- yes, it is. If I run the service project by itself, then hit it with some test client, breakpoints get hit correctly. So debugging on the service works. I can even explictly "attach to remote process" and debug the service that way. But WCF will not automatically step from the client to the service. Has anyone seen a similiar issue?

A: 

Are you using the automatic WCF service hosting feature in Visual Studio? You can check this by opening the project properties of your WCF service project and navigating to the WCF Options tab. Is the Start WCF Service Host when debugging another project in the same solution checkbox checked? If it is, then this explains the problem.

What's happening is that when you run your client, a separate process is created to automatically host your WCF service. Because it is a separate process, you will not be able to "step into" it when debugging your client. You'll have to run two separate debug sessions, one for your service and one for your client.

An easy way to do this is to put a call to System.Diagnostics.Debugger.Break() in the startup logic for your service. When your service is automatically started by the WCF service host, you'll be prompted to debug it, allowing you to open a second instance of Visual Studio for it's debug session.

Matt Davis
I think this would only apply if the WCF service is self-hosted, which would mean NOT inside IIS, the VS Dev server, or the WCF Service Host. Or more simply, what the OP is asking about usually works "out of the box" in a solution with a WCF project - you can just step into it.
msulis
A: 

I've had this happen as well. Curiously it seems to happen after I make changes to the build configuration (from x64 to x86). Here's how I've been able to fix it:

  1. Right-click the solution, select Properties.
  2. Under "Startup Project" switch from "Single startup project" to "Multiple startup projects".
  3. Set Action to "Start" for the WCF project.

Even though I'm hosting the project in the local IIS server (not the VS Development Server) this solves it, which is a little puzzling. I suspect that setting a project to "Start" also causes VS to attach to the process for debugging.

http://msdn.microsoft.com/en-us/library/bb157685.aspx

msulis