WCF in IIS with Websites that have Multiple Identities

Error Description: "This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection.
Parameter name: item"

A fantastic<sarcasm> thing you may come across using WCF when you deploy to a production network is that your networks group uses more than one identity per website (most likely due to different host headers).  Below is a picture of what it looks like in IIS.  You get there when you right click on the website (in IIS) and select [Properties], then click {Advanced} under the [Web Site Identification] section on the [Web Site] Tab.  If you have more than one, then you are not going to be able to use WCF by default.  It doesn't matter if they are different ports either, you will still have the error above.

MultipleWebSiteIdentities

 

WCF does not allow multiple service base addresses for each endpoint by default in v1.  Wenlong Dong mentions:

In WCF V1, only one base address is supported for each protocol. So if there are two or more bindings for HTTP is specified, you will get an ArgumentException on the service side with error message “Collection already contains an address with scheme http”.

 

So how do you get around this problem? Microsoft has made WCF extendable, which is a great thing when you have limitations in v1 like this.  http://msdn2.microsoft.com/en-us/library/aa702697.aspx 

Rob Zelt has a great post here about how to actually answer the problem above.  Make sure you check out his comments as well.

 

Here is my rendition of Rob's code in VB.

This is the CustomServiceFactory.vb:

Imports System.ServiceModel
Imports System.ServiceModel.Activation

Public Class CustomServiceFactory : Inherits ServiceHostFactory

    Private baseAddressIndex As Integer = 0

    Protected Overrides Function CreateServiceHost(ByVal serviceType As System.Type, ByVal baseAddresses() As System.Uri) As ServiceHost
        Return New ServiceHost(serviceType, baseAddresses(baseAddressIndex))
    End Function

End Class 

 This is an example of what is in the *.svc file:

<%@ ServiceHost Language="VB" Debug="true" 
    Service="Organization.Services.TempService"
    Factory="Organization.Services.CustomServiceFactory" %>

 

From what you see above, the answer is to basically filter out all of the baseAddresses and only pass one to the Service Host constructor.  Rob used a CustomHost in his example, but I found that it wasn't required. As you can see it is a very simple solution and it is all you need to get up and running with a website that has multiple identities.

Other References: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=373333&SiteID=1 and http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1710821&SiteID=1

posted @ Tuesday, October 02, 2007 11:56 PM

Print

Comments on this entry:

# re: WCF in IIS with Websites that have Multiple Identities

Left by David Barrett at 1/24/2008 12:29 PM
Gravatar
Fantastic! Thanks for sharing. Got me out of a bind.

# re: WCF in IIS with Websites that have Multiple Identities

Left by Robz at 1/24/2008 6:52 PM
Gravatar
Glad to help out.

# re: WCF in IIS with Websites that have Multiple Identities

Left by Phil at 3/27/2008 11:05 AM
Gravatar
Can't this be addressed via IIS?
i.e. Create a new web site with the 1 host header that you wan't to use for your web service, point it at the same physical directory as the original site, and remove the host header from the original site.

# re: WCF in IIS with Websites that have Multiple Identities

Left by Robz at 3/27/2008 9:32 PM
Gravatar
You could do that, but that is saying you have control over that. In our case and the case of probably many, we may not have control over the environments once they promote above test.

You may also find yourself maintaining two mirrored IIS web sites when you can solve it with one web site with two host headers. ;D

# re: WCF in IIS with Websites that have Multiple Identities

Left by Phil at 3/28/2008 5:35 AM
Gravatar
The web sites aren't mirrored - they point to the same physical deployment - the difference is only in the IIS configuration.

This approach also means that the host header can be changed in IIS without requiring any change to the application.

# re: WCF in IIS with Websites that have Multiple Identities

Left by Fervent Coder at 3/28/2008 6:40 AM
Gravatar
I guess I would have to see what you mean because I was thinking the second website could point to the same root, but each of the virtual directories would need to be recreated, thus maintaining two sites instead of one. I don't think you are going to that level though. The second site must only be for the WCF configuration.

# re: WCF in IIS with Websites that have Multiple Identities

Left by Rick at 4/17/2008 3:16 PM
Gravatar
So, then how do you get say www.domain.com and domain.com to work?

# re: WCF in IIS with Websites that have Multiple Identities

Left by Fervent Coder at 4/18/2008 12:52 AM
Gravatar
@Rick: It depends on what you put into the host headers. Are you putting both of these in your host headers or just the domain.com?

# re: WCF in IIS with Websites that have Multiple Identities

Left by Ayo at 4/28/2008 6:45 PM
Gravatar
@Fervent Coder: I'm having the same issue as Rick. I'm putting in both www.domain.com and domain.com into Advanced Web Site Identification options in IIS.

# re: WCF in IIS with Websites that have Multiple Identities

Left by Fervent Coder at 4/28/2008 7:12 PM
Gravatar
Perhaps to alleviate the issue at hand, put one in and put a permanent redirect (301 I believe) on the other.
There is a thread going right now with Microsoft you might want to check out: https://connect.microsoft.com/wcf/feedback/ViewFeedback.aspx?FeedbackID=322896

# re: WCF in IIS with Websites that have Multiple Identities

Left by chris chandler at 4/28/2008 8:34 PM
Gravatar
@fervent coder: I use the 301 and it works great, luckily I get control of my prod cluster and only have like 3 websites on it, so I just have 6 iis nodes, 3 that 301 to the other 3 and 3 that implement custom service factory on ports 8080, 8081, 8082. Then my reverse proxy load balances the 3 ports.

Although, I guess I could just handle the domain.com requests at the proxy, and be done with, maybe thats what we are missing? Why don't more .net deployments include proxies like the open source guys?

# re: WCF in IIS with Websites that have Multiple Identities

Left by Fervent Coder at 4/30/2008 6:11 PM
Gravatar
@Chris: Good question. And one I don't have the answer to. :D

Are these open source deployments for the web apps including proxies? I wouldn't want to mix architecture in too far with web app. That would be more of an IIS type setting to me, but perhaps I am not quite following what you are saying. :D

# re: WCF in IIS with Websites that have Multiple Identities

Left by Chris at 7/21/2008 7:14 AM
Gravatar
Solution in .Net Fx3.5: BaseAddressPrefixFilters

http://blogs.msdn.com/rampo/archive/2008/02/11/how-can-wcf-support-multiple-iis-binding-specified-per-site.aspx

# re: WCF in IIS with Websites that have Multiple Identities

Left by Chris at 7/21/2008 7:18 AM
Gravatar
Solution in .Net Fx3.5: BaseAddressPrefixFilters

http://blogs.msdn.com/rampo/archive/2008/02/11/how-can-wcf-support-multiple-iis-binding-specified-per-site.aspx

Your comment:



 (will not be displayed)


 
 
 
Please add 7 and 8 and type the answer here:
 

Live Comment Preview:

 
«July»
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789