How to Self-Host WCF

Self-hosting is best suited for development and debugging scenarios in which you want maximum flexibility and you want to get the service running as quickly as possible. When readying for deployment you should choose between hosting in a Windows service or
in IIS.

Use the following methods to self-host your WCF service in any .NET application:

Create a method to start the service, as shown in the following code example

// Host the service within the application.
public static void Main()
{
// Create a ServiceHost for the CalculatorService type.
using (ServiceHost serviceHost =
new ServiceHost(typeof(Service1)))
{
// Open the ServiceHost to create listeners
// and start listening for messages.
serviceHost.Open();
Console.ReadLine();
}
}

In the self-hosted case, you must specify the base address. This example shows how to configure the config file.