- Open Visual Studio
- Open WCF service project that you created OR create one based on instructions here.
- Add a new project to the current solution: Right click Solution on Solution Explorer > Add > Add New Project
- Select Console Application template under Visual C# > Windows templates
- Change the project name to ConsoleHost and click OK
- In Solution Explorer, under ConsoleHost project, right click References and select Add Reference...
- In the Reference Manager window, add reference to System.ServiceModel and to ProductServiceLibrary solution
- Add using System.ServiceModel;
- Add using ProductServiceLibrary;
- Add the following code in Program.cs file
class Program
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(ProductService));
try
{
host.Open();
Console.ReadKey();
host.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
host.Abort();
}
Console.ReadKey();
}
}
Configure Service and Service Endpoints
- Right click on App.config > Edit WCF Configuration > under services summary click Create a New Service...
- click browse, go out of the current folder, select ProductServiceLibrary > bin > Debug > ProductServiceLibrary.dll > ProductServiceLibrary.ProductService. Click next.
- Keep the default ProductServiceLibrary.IProductService contract and click next.
- Keep the default selection HTTP and click next.
- Keep the default Basic Web Services interoperability and click next
- For address type http://localhost:8733/Design_Time_Addresses/ProductServiceLibrary/ProductService/basic and click Next and then click Finish
- Save and Exit Microsoft Service Configuration Editor
- Right click on the ConsoleHost project and Set as StartUp project.
- Right click on ProductService project > properties > WCF Options > Uncheck Start WCF Service Host when debugging another project in the same solution
- Run Service Host