title: Multiple hostnames on a single machine with IIS and self-hosted WCF
body: <p>I have two hostnames, a domain and subdomain (<code>example.com</code> and <code>service.example.com</code>) both pointing to a single (Windows 2008) server. The server is running IIS 7 (hosting an ASP.NET web site) and a self-hosted WCF service. I want IIS to handle requests to <code>http://example.com</code> and the WCF service to handle requests to <code>http://service.example.com</code>.</p>
  
  <p>The problem is that if the service is running, it "intercepts" all HTTP requests regardless of the Host header. In other words, if I visit <code>http://example.com</code> in a web browser, I get the WCF "You have created a service" page instead of the ASP.NET site. If the service is not running, IIS handles the requests as expected.</p>
  
  <p>The IIS site has a single HTTP binding on port 80, with the <code>example.com</code> hostname specified.</p>
  
  <p>The relevant portion of the service's app.config file is as follows. I have tried all three <code>hostNameComparisonMode</code> values with no luck.</p>
  
  <pre><code>&lt;bindings&gt;
    &lt;basicHttpBinding&gt;
      &lt;binding name="BasicHttp" hostNameComparisonMode="Exact"&gt;
        &lt;security mode="None" /&gt;
      &lt;/binding&gt;
    &lt;/basicHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;services&gt;
    &lt;service behaviorConfiguration="ExampleServiceBehavior" name="Example.Service"&gt;
      &lt;endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttp" contract="Example.IService" /&gt;
      &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
      &lt;host&gt;
        &lt;baseAddresses&gt;
          &lt;add baseAddress="http://service.example.com/" /&gt;
        &lt;/baseAddresses&gt;
      &lt;/host&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  </code></pre>