Let's follow these steps to create a self-hosted console application:
- First, add a new project of type Console Application, inside the solution, and name it CH09.SelfHostingDemo.
- Now, right-click on the References node, and add the project reference of the service (CH09.EmployeeService):
- Also add the assembly reference of System.ServiceModel into the console application project.
- From Solution Explorer, navigate to the Program.cs file.
- Add the following using namespaces inside the class file:
using CH09.EmployeeService.Services; using System; using System.ServiceModel; using System.ServiceModel.Description;
- Now we need to define the service URL so that we can access it from the host. Create a static member variable inside the Program.cs class file, as follows:
private static Uri serviceUrl = new Uri( "http://localhost:59795/Services/EmployeeService");
- The Program class contains a static Main method. Replace the definition with the following...