Preventing the WCF Service Host from launching in Visual Studio 2008

One of the great new features of Visual Studio 2008 is the new tools for WCF developers. No longer is it necessary to code up your own test host and test client applications to test your service. This functionality is provided for you automatically thanks to the WCF Service Host and WCF Test Client. This significantly improves developer productivity with regard to the development of the service. Unfortunately, if you’re going to be hosting your service in a custom host, such as a windows application or console application (probably for debugging purposes since these are generally not practical choices for hosting) then you will run into a little snag if you add that project to the same solution.

The snag you are going to run into is the WCF Service Host running at the same time as your custom host application when you press F5 to run your application. When your custom host application initializes the WCF stack, you will likely see an AddressAlreadyInUseException. This is happening because the WCF Service Host is already listening on the same address.

Unfortunately, there is not a switch in the Visual Studio environment that resolves this problem. So, you have to go to the project file for your service and make a small change, which I’ll describe here.

1. Right-click the WCF service project (not the custom host project) in Solution Explorer and select Open Folder in Windows Explorer.

2. In Windows Explorer, right-click the project file (.csproj) and select Open With | Notepad (if Notepad is not an option you may need to browse to it).

3. In Notepad, look for the <ProjectTypeGuids> element and delete it.

 

image

4. In Notepad select File | Save on the menu to save the change and then File | Exit to close Notepad.

 

5. Go back to your Visual Studio 2008 window. When you activate the window, you will see a dialog prompting you to reload the project file. Click the Reload button to reload the project file.

6. Press F5 to run your custom host application.