- Open WCF RESTful 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, System.ServiceModel.Web, and ProductServiceLibrary solution
- Add using System.ServiceModel;
- Add using System.ServiceModel.Web;
- Add using ProductServiceLibrary;
- Add the following code in Program.cs file
class Program
{
static void Main(string[] args)
{
WebServiceHost host = new WebServiceHost(typeof(ProductService));
try
{
host.Open();
Console.ReadKey();
host.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
host.Abort();
}
Console.ReadKey();
}
}
Configure Service
- Open App.config and add the following code
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="ProductServiceLibrary.ProductService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/ProductServiceLibrary/ProductService" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Test the application
- Right click on the ConsoleHost project and Set as StartUp project.
- Run Service Host