This project is read-only.

How to host Web API in Windows Service

Topics: Web Api
Oct 20, 2011 at 2:32 AM
Edited Oct 20, 2011 at 2:32 AM

I have several resources that I'd like to expose using the WCF Web API.  I've investigated the Web API using a Web host but our services all run as Windows Services in production so it's time for me to put the tests aside and verify that everything will work as we need it.  I've looked as the sample app here: but this does not work with the current version (preview 5) because the HttpConfigurableServiceHost class is not accessible from our code.

One of the most appealing aspects of the Web API is the simple startup using MapServiceRoute and the new WebApiConfiguration.  I don't see, however, a way to define the base url and port for the services.  Obviously, hosting the service in IIS eliminates this because we configure this information in IIS.  How can I accomplish this when hosting in a Windows Service?


Oct 20, 2011 at 8:03 AM


Pedro Félix’s has a blog post about WCF Web API Self-hosting here:

maybe that can lead you in the right direction....




Oct 20, 2011 at 6:58 PM

var host = new HttpServiceHost(typeof(MyWebApi), config, baseAddress);


Daniel Roth