Hosting the WCF Service in .NET Executable


This post explains how to host a WCF service that we defined in the previous article WCF sample in VS 2008. Specifically we host the WCF service in .NET console application.

1. Add the Console application project called, Host, to the solution

2. Add System.ServiceModel .NET, System.Configuration Assemblies to the

    Host  Project.

3. Add the WCF Service project to the Host project


4. Write the following code which needed to provide a host for the WCFEmployee service


5. The above code retrieves the base addresses from the configuration file and the addresses of WCF endpoints are relative to the base addresses.

6. Add the application configuration file named app.config to the Host project

    Modify the content as follows


appSettings section provides the address for the HTTP and TCP protocols.

System.serviceModel section for configuring the WCF endpoints. Here we add the address, binding and contract which constitutes an endpoint.

7. Run the Host Project it shows the following window


8. You can test the host service by clicking the http://localhost:8000/EmployeeService/ and you will see the following window


Leave a reply

Why ask?