The service ‘/MyService.svc’ cannot be activated due to an exception during compilation.
The exception message is: This collection already contains an address with scheme http
If you’re like me, when deploying a WCF service to a production site and seeing this error… you’re thinking WTF? Especially knowing it worked in your testing environment.
To keep this post short and sweet, the idea to understand is that www.mydomain.com and mydomain.com are two separate addresses. Simply put, most people have one site setup in IIS to handle both addresses (usually identified by different bindings). However IIS treats them uniquely but pools the settings together.
Therefore the Service Model is stating that it already has this service defined, why are you doing it twice?
After doing some research and some trial and error, the answer is actually simple. Your Service Model config section of the web.config (the service hosting environment) needs to be told explicitly what base address it should respond to. This can be accomplished by simply adding the following:
From my testing, this config setting handled both www.mydomain.com/MyService.svc and mydomain.com/MyService.svc calls. Regardless, usually your proxy points to one of the two, but it’s nice to know that both still work!