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

Restricting Export Options in Report Manager


This doesn't really seem to be out there a lot, but a colleague of mine found this for me recently.

http://sqljunkies.com/WebLog/roman/archive/2004/12/12/5506.aspx



Now if we can figure out how to override the default output so we can tell SQL Server Reporting Services (SSRS) not to ignore whitespace.  Reports look great in everything BUT HTML when you want more than one space on items.
Twitter