WCF Config element: baseAddressPrefixFilters

2020-03-19 04:36发布

问题:

I have read the documentation for this element but still fail to understand what its purpose is. Here is a sample of how I've seen it used in examples:

<serviceHostingEnvironment>
  <baseAddressPrefixFilters>
    <add prefix="http://localhost:5100/"/>
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>

I want to understand what this does that the base addresses in a service node doesn't do. I don't understand what this element is actually used for.

回答1:

A WCF service host will only allow a single base address per scheme (HTTP in this case). Now if you deploy a WCF service on an IIS configured with multiple base addresses, for example http://www.example.com and http://example.com you will see an error. Using the baseAddressPrefixFilters you can filter one of the two base addresses and your service will run just fine.