WCF Web API–IIS Hosting

This is the fourth post on a series about the new WCF Web API – Preview 4.

In the second post, I described how to create self hosted services. In this post, I’ll show how to host on IIS.

1. Create a empty ASP.NET web application and map a IIS site or virtual directory into it. On my development environment, I usually create a new site for each project and use the hosts file to map the site name to

2. Ensure the following on the web.config

  <!-- Ensure the UrlRoutingModule -->
    <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRoutingModule"
               type="System.Web.Routing.UrlRoutingModule, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

  <!-- Enable ASP.NET compatibility -->
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

The UrlRoutingModule is used to route the requests into the WCF runtime.

3. Add the following route map to the application start (global.asax)

public class Global : System.Web.HttpApplication
    protected void Application_Start(object sender, EventArgs e)

where TodoResource is the resource class (service class) and “todos” is the base path.

The MapServiceRoute extension methods adds a ServiceRoute to the RouteTable.Routes collection. This ServiceRoute uses a host factory that will produce a HttpConfigurableServiceHost. This host derives from the new HttpServiceHost, introduced on a previous post.

The MapServiceRoute also accepts an IHttpHostConfigurationBuilder, which can be used to configure the service. This configuration model, also applicable to self-hosting scenarios, will be the subject of a future post.

4 thoughts on “WCF Web API–IIS Hosting

  1. Pingback: HTTP content classes « Pedro Félix’s shared memory

  2. steve

    Hi, thank you. A couple of questions:

    where TodoResource is the resource class (service class) and “todos” is the base path.

    what is the “resource class”? “base path” of what?

    What files must be deployed besides my project DLL?



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s