Fervent Coder

Coding Towards Utopia...by Rob Reynolds
posts - 278 , comments - 431 , trackbacks - 0

My Links

News


Rob Reynolds

Subscribe to Fervent Coder RSS
Subscribe to Fervent Coder by Email

About Me

I manage several open source projects. Need...
   ...package management for Windows?
   ...automated builds?
   ...database change management (migrations)?
   ...your application to check email?
   ...a monitoring utility?

I also write for



Like what you are reading? Want to buy me a cup of coffee?
PayPal - The safer, easier way to pay online!

Archives

Post Categories

Sites

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

Print | posted on Tuesday, October 2, 2007 11:56 PM | Filed Under [ Code ApplicationsToysOther WCF ]

Feedback

Gravatar

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

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

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

Glad to help out.
1/24/2008 6:52 PM | Robz
Gravatar

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

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.
3/27/2008 11:05 AM | Phil
Gravatar

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

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
3/27/2008 9:32 PM | Robz
Gravatar

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

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.
3/28/2008 5:35 AM | Phil
Gravatar

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

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.
3/28/2008 6:40 AM | Fervent Coder
Gravatar

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

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

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

@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?
4/18/2008 12:52 AM | Fervent Coder
Gravatar

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

@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.
4/28/2008 6:45 PM | Ayo
Gravatar

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

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
4/28/2008 7:12 PM | Fervent Coder
Gravatar

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

@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?
4/28/2008 8:34 PM | chris chandler
Gravatar

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

@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
4/30/2008 6:11 PM | Fervent Coder
Gravatar

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

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

7/21/2008 7:14 AM | Chris
Gravatar

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

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
7/21/2008 7:18 AM | Chris
Comments have been closed on this topic.

Powered by: