tags:

views:

11878

answers:

4

I built a web application containing a wcf service contract and a silverlight control which makes calls to that wcf service. On my development and test servers it works great. When I deploy to our live server and run the application I get an exception of type System.ServiceModel.ServiceActivationException which states that the service can not be activated due to an exception during compilation. The exception is "This collection already contains an address with scheme http. There can be at most one address per scheme in this collection."

I read that this exception may be thrown if the web site has more than one host header, which is try on our live server. Apparently WCF services hosted in IIS can have only one base address. How can I get around this issue?

+1  A: 

Did you saw this - http://community.discountasp.net/default.aspx?f=24&m=16709&p=1 ?

Mike Chaliy
Thanks. I'm going to continue searching to see if there is a not code solution. Something that can be done in configuration because this is going to affect any project we do I'm hoping to not have to write custom code.
Jeremy
404 Not Found ...
Rafe Lavelle
+29  A: 

Summary,

Code solutions: Here and Here

Configuration solutions: Here

With the help of Mike Chaliy, I found some solutions on how to do this through code. Because this issue is going to affect pretty much all projects we deploy to a live environment I held out for a purely configuration solution. I eventually found one which details how to do it in .net 3.0 and .net 3.5.

Taken from the site, below is an example of how to alter your applications web config:

<system.serviceModel>
    <serviceHostingEnvironment>
        <baseAddressPrefixFilters>
            <add prefix=”net.tcp://payroll.myorg.com:8000”/>
            <add prefix=”http://shipping.myorg.com:9000”/&gt;
        </baseAddressPrefixFilters>
    </serviceHostingEnvironment>
</system.serviceModel>

In the above example, net.tcp://payroll.myorg.com:8000 and http://shipping.myorg.com:9000 are the only base addresses, for their respective schemes, which will be allowed to be passed through. The baseAddressPrefixFilter does not support any wildcards .

The baseAddresses supplied by IIS may have addresses bound to other schemes not present in baseAddressPrefixFilter list. These addresses will not be filtered out.

Dns solution (untested): I think that if you created a new dns entry specific to your web application, added a new web site, and gave it a single host header matching the dns entry, you would mitigate this issue altogether, and would not have to write custom code or add prefixes to your web.config file.

Jeremy
Adding the base address prefix filter to the web.config worked perfectly. Thanks Jeremy!
Mike737
I can't think of any reason why one would want such a restriction, much less the default setting...
pbz
This worked great for me too! Thanks! Seems like it's a common problem when hosting WCF on a shared host.
NovaJoe
I'm starting to think badly about WCF in combination with ASP.net and web services accessed through JavaScript. I had much less problems with plain old ASMX services...
Juri
this worked perfectly. Thank jeremy.... :)
nRk
+3  A: 

In .Net 4, you can use the multipleSiteBindingsEnabled option:

<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"
    </serviceHostingEnvironment>
</system.serviceModel>

Then, you won't have to specify each address.

http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehostingenvironment.multiplesitebindingsenabled.aspx

ericvg
Yes, but this only works with .NET 4.0 and higher. Not able to use this with .NET 2.0/3.0/3.5 sites.
Bytemaster
+1  A: 

Thanks for the 4.0 solution. multipleSiteBindingsEnabled worked great!

Dan
You should enter this type of statement as a comment, not as an answer
Jeremy