简体   繁体   中英

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

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 ac# 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.

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>

One of the solution I found previously was to add something like this:

  <serviceHostingEnvironment>
    <baseAddressPrefixFilters>
      <add prefix="http://localhost:8000"/>
    </baseAddressPrefixFilters>
  </serviceHostingEnvironment>

And then specifying the endpoint address absolutely. This didn't seem to have an effect but I was still using baseAddr in the constructor as shown above.

The solution for me was to remove baseAddr from the constructor.

This can also occur if you have multiple bindings on the same IIS site with different domain names/ports. I resolved the issue by removing the extra named binding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM