IIS tricking me and the WCF service again

Once upon a time my team started implementing a thin client for an SaaS solution.

It happened, that we needed webservices. Cool, just add some traditional asxm webservice, working fine.

Afterwards the customer came and asked for some domain change.
No problem, the installer added additional domains to the IIS bindings to the same protocol for backwards compatibility.

We understood the need for a service API e.g. for performance or automated testing to access some business functionality through a carefully crafted Service API layer.
However we have visioned service with WCF technology. Brighter, nicer, more trendy ;)

Then came the suprise:

Server Error in '/Services/InternalApiService' Application.
This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection.
Parameter name: item
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection.
Parameter name: item

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentException: This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection. 
Parameter name: item]
   System.ServiceModel.UriSchemeKeyedCollection.InsertItem(Int32 index, Uri item) +11526110
   System.Collections.Generic.SynchronizedCollection`1.Add(T item) +67
   System.ServiceModel.UriSchemeKeyedCollection..ctor(Uri[] addresses) +49
   System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +129
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +28
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +331
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +11666348
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +42
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +479

[ServiceActivationException: The service '/Services/EnterpriseApiService/EnterpriseApiService.svc' cannot be activated due to an exception during compilation.  The exception message is: This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection. 
Parameter name: item.]
   System.ServiceModel.AsyncResult.End(IAsyncResult result) +11536522
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176
   System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +278
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

After some minutes of painful debugging and staring at the stack-trace we have discovered the root cause.
One cannot add a WCF service to a site with multiple bindings to same protocol.
It clearly seems to be a design problem with WCF, however as I am not an expert, wouldn't judge.

e.g.: http://subdomain1.domain.com & http://subdomain2.domain.com

Anyway, it is a painful constraint.

Workaround is easy: create a dedicated web site....

No comments:

Post a Comment