Search code examples
.netwcf

Breakpoint not being hit while debugging WCF application


I have a WCF application and a console application.

I published WCF application in a separate folder. Added a Virtual Application in IIS.

In console application, I added a Service Reference to the site added in IIS.

With this, I am unable to debug WCF application and the breakpoint is not hitting.

I opened two instances of VS. In once instance, I executed WCF application and in the other, the console application.

Why the WCF breakpoints not hitting?


Solution

  • There is no need to publish the WCF application manually to an IIS for development/debugging purposes. The hosting part is already built-in into Visual Studio.

    If you want to connect a client application to a WCF Service, there are two ways I can think of:

    Method 1: Use a Service Reference

    That is the quickest approach and works in most cases out of the box (You have chosen this one).

    You need to have a solution file with client and server projects similar to this one:

    enter image description here

    In the "Add Service Reference" Dialog, click "Discover". This will look for WCF services in your solution (this services don't need to be started).

    Side note: If you click on "Go", only a started service can be found.

    enter image description here

    You should see your service in the "Services" section and the Address Field is automatically filled out for you with the address Visual Studio will use for local debugging.

    enter image description here

    Continue adding the service as you always do...

    Visual Studio will automatically update the client's app.config file.

    If you start the console application only, Visual Studio will also start the service in background for you. You are able to step into the service operation by hitting F11 without explicit setting a breakpoint.

    Method 2: Without using service references

    Clicking on "Add service Reference" will generate code based on the current data contracts. If you change that definition (types, operations, etc.), you have to generate it again.

    If you are the owner of both, client and service, then you can create a dynamic proxy at runtime using WCF Channelfactory.

    You have to extract the Service contract and Data contracts only to a new assembly and share it with client and server. There is no code generation necessary and this way you will always be safe at compile time. See here for more information.

    Because VS is not aware of any service references, you have to start both projects by yourself. Just set multiple startup projects in your solution and press F5. But in this case, you have to set a breakpoint in your service application.