C# – Getting Error “This collection already contains an address with scheme http” with WCF on local machine

cnetwcf

I'm trying out WCF for the first time and getting the following error when I try to instantiate the host:

This collection already contains an address with scheme http…

I have found a lot of other references to this and tried some of the solution to no avail. One fairly common thread that does not apply to me is that the problem is on a web server of some sort. I'm just running everything from my local machine.

One interesting symptom I found is that I'm developing a c# Forms app. Originally my top level form object inherited my service interface instead of a separate Service class. When I implement this way, there is no error on the host side but I have been having trouble on the client side.

Based on this solution:
How to solve "The ChannelDispatcher is unable to open its IChannelListener" error?

…I decided to separate the service host into a separate object. That's when I start seeing the problem.

The ServiceContract is simple enough:

[ServiceContract]
public interface ISSAService
{
    [OperationContract]
    void CreateSpaMonitor();
}

I instantiate the service like this:

        Uri baseAddr = new Uri("http://localhost:8000/SSAService");
        ServiceHost localHost = new ServiceHost(typeof(SSAService), baseAddr);

Where SSAService is the implementation of the Service interface.

If I change the second line to the following (and implement the interface…) the error goes away:

        Uri baseAddr = new Uri("http://localhost:8000/SSAService");
        ServiceHost localHost = new ServiceHost(typeof(SSAManager), baseAddr);

Where SSAManager is my top level Forms class…

Then I run into a client side problem which is where I started….

I have tried changing the port number and that doesn't seem to affect anything.

I'm new to WCF so maybe I'm missing something obvious.

Thanks.

Best Answer

I was getting this error:

This collection already contains an address with scheme https. There can be at most one address per scheme in this collection. If your service is being hosted in IIS you can fix the problem by setting 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' to true or specifying 'system.serviceModel/serviceHostingEnvironment/baseAddressPrefixFilters'. Parameter name: item

I resolved it by doing the following to my web.config. Perhaps something changed in the .NET Framework 4 which is requiring this line, since I didn't need it before:

<system.serviceModel>
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />           
    <!--  Rest of the system.serviceModel content omitted for brevity--->

<system.serviceModel>