Search code examples
c#asp.netwcfwcf-binding

dynamically set WCF baseAddressPrefixFilters


I have a WCF service that I am deploying in a shared hosting environment. Because of this I have to specify baseAddressPrefixFilters (see answer here for why this is necessary). Setting the base address prefix filters happens in the web.config like so...

<serviceHostingEnvironment>
  <baseAddressPrefixFilters>
    <add prefix="http://example.com"/>
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>

The problem is that I have multiple environments that are configured this way with their own urls (i.e. dev, test, prod)

I tried the following with no luck...

<serviceHostingEnvironment>
  <baseAddressPrefixFilters>
    <add prefix="http://dev.example.com"/>
    <add prefix="http://test.example.com"/>
    <add prefix="http://example.com"/>
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>

So the question is how do I set the baseAddressPrefixFilter dynamically at runtime?


Solution

  • If you are running under IIS7, this is a good walk through of the problem and solution. If not, the information for the WCF side is still what you need to know to resolve your issues.

    http://keithelder.net/2008/04/28/configuring-wcf-and-iis-7-with-http-bindings-and-multiple/

    Have you looked at the ServiceHostFactory? We used this in our 3.0 services to work with the different host headers.

    http://blogs.msdn.com/rampo/archive/2007/06/15/supporting-multiple-iis-bindings-per-site.aspx