Click here to Skip to main content
13,291,690 members (57,454 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 4 Dec 2013

SharePoint: Getting "This collection already contains an address with scheme HTTP" Error When Creating a Custom WCF Service

, 4 Dec 2013
Rate this:
Please Sign up or sign in to vote.
How to fix this error.


The problem is caused by the fact that IIS supports specifying multiple IIS bindings per site (which results in multiple base addresses per scheme, in our case HTTP), but a WCF service hosted under a site allows binding to only one base address per scheme.

Multiple addresses example (in our case two):



Create a custom service factory to intercept and remove the additional unwanted base addresses that IIS was providing.

  1. Add the custom service factory to your Custom.svc file
  2. <%@ServiceHost language="c#" Debug="true" 
      Service="MySolution.Services.CustomService, $SharePoint.Project.AssemblyFullName$"
      Factory="MySolution.Core.CustomHostFactory", $SharePoint.Project.AssemblyFullName$ %>

    * Don’t forget to add the assembly full name: $SharePoint.Project.AssemblyFullName$ or you’ll get “The CLR Type ‘typeName’ could not be loaded during service compilation” error.

  3. Create a custom factory by inheriting from ServiceHostFactory and overriding the CreateServiceHost method.
  4. By using the current request host name you can check which base address to use, and if no host name found, use the first one.

    public class CustomServiceHostFactory : ServiceHostFactory
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
            string hostName = HttpContext.Current.Request.Url.Host;
            foreach (Uri uri in baseAddresses)
                if (uri.Host == hostName)
                    return new ServiceHost(serviceType, uri);
            return new ServiceHost(serviceType, baseAddresses[0]);
    public class CustomHost : ServiceHost
            public CustomHost(Type serviceType, params Uri[] baseAddresses)
                : base(serviceType, baseAddresses)
            { }
            protected override void ApplyConfiguration()

Hope you’ll find this post helpful.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Alex Choroshin
Software Developer (Senior) E4D
Israel Israel
Alex Choroshin is working as a Consultant/Web Developer at LogoUi company , he has a vast experience developing client side solutions and single page application using the latest web technologies: HTML5, CSS3 , AngularJS, JQuery, SignalR, ASP.NET MVC4, Web API, NodeJS etc.

Also experience with the SharePoint 2010 & SharePoint 2013 platform encompassing all the aspects of SharePoint architecture and development.

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 4 Dec 2013
Article Copyright 2013 by Alex Choroshin
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid