Wednesday, October 28, 2009

How to debug a Self-hosted WCF Service

After manually attaching the debugger to the hosting process to debug the code, I got this error when I try to debug a self-hosted WCF service:
System.ServiceModel.AddressAlreadyInUseException: The TransportManager failed to listen on the supplied URI using the NetTcpPortSharing service: the URI is already registered with the service.

As the self-hosted WCF Service (runs as a running process [Windows Service])] has used port number XXXX already, when Visual Studio attempts to fire the WCF Service Host again on the same port, the conflict occurs as the URI has been used up already.

Starting the Net.Tcp Port Sharing Service did not help either.

The work around to debug this issue in steps:
1.) Unload the project that contains the code for the host.
2.) Attach the process to the windows/self-hosting service. (At this point, WCF Service Host does not complain that the URI has been used as it attaches to the running self-hosting service instance)
3.) Reload the unloaded project and set breakpoints to step through code.

No comments:

Post a Comment