简体   繁体   English

获取错误“此集合已包含带有方案http的地址”,本地计算机上有WCF

[英]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: 我第一次尝试WCF并在尝试实例化主机时收到以下错误:

This collection already contains an address with scheme http... 此集合已包含带有方案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. 一个相当常见的线程不适用于我,问题出在某种Web服务器上。 I'm just running everything from my local machine. 我只是在本地机器上运行所有东西。

One interesting symptom I found is that I'm developing ac# Forms app. 我发现一个有趣的症状是我正在开发ac#Forms应用程序。 Originally my top level form object inherited my service interface instead of a separate Service class. 最初我的顶级表单对象继承了我的服务接口而不是单独的Service类。 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? 基于此解决方案: 如何解决“ChannelDispatcher无法打开其IChannelListener”错误?

...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很简单:

[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. 其中SSAService是Service接口的实现。

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... 哪里SSAManager是我的顶级Forms类...

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. 我是WCF的新手,所以也许我错过了一些明显的东西。

Thanks. 谢谢。

I was getting this error: 我收到了这个错误:

This collection already contains an address with scheme https. 此集合已包含方案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'. 如果您的服务是在IIS中托管的,则可以通过将'system.serviceModel / serviceHostingEnvironment / multipleSiteBindingsEnabled'设置为true或指定'system.serviceModel / serviceHostingEnvironment / baseAddressPrefixFilters'来解决问题。 Parameter name: item 参数名称:item

I resolved it by doing the following to my web.config. 我通过对web.config执行以下操作来解决它。 Perhaps something changed in the .NET Framework 4 which is requiring this line, since I didn't need it before: 可能在.NET Framework 4中发生了一些变化,这需要这一行,因为我以前不需要它:

<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. 这似乎没有效果,但我仍然在构造函数中使用baseAddr,如上所示。

The solution for me was to remove baseAddr from the constructor. 我的解决方案是从构造函数中删除baseAddr。

This can also occur if you have multiple bindings on the same IIS site with different domain names/ports. 如果在具有不同域名/端口的同一IIS站点上有多个绑定,也会发生这种情况。 I resolved the issue by removing the extra named binding. 我通过删除额外的命名绑定来解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WCF Web.config 错误:“此集合已包含一个带有方案 http 的地址” - WCF Web.config Error : “This collection already contains an address with scheme http” 集合已包含方案net.tcp的地址 - Collection Already Contains Address with scheme net.tcp WCF错误。 找不到与绑定WSHttpBinding的端点的方案http匹配的基地址 - Error with WCF. Could not find a base address that matches scheme http for the endpoint with binding WSHttpBinding WCF 异常:找不到与端点的方案 http 匹配的基地址 - WCF Exception: Could not find a base address that matches scheme http for the endpoint Wcf https ssl中的服务端点出错。 使用绑定WebHttpBinding找不到与方案http匹配的终点的基址 - Error With service endpoint in wcf https ssl. Cannot find base address that matches scheme http for the end point with binding WebHttpBinding 获取客户端机器的mac地址时出错 - Error in getting mac address of client machine 仅从本地计算机成功连接我的WCF服务,除非指定了计算机IP地址而不是本地主机 - Succeed to connect my WCF service only from local machine unless machine ip address is specified instead of localhost WCF找不到与绑定MetadataExchangeHttpBinding的端点的方案http匹配的基地址 - WCF Could not find a base address that matches scheme http for the endpoint with binding MetadataExchangeHttpBinding IIS托管具有SSL安全性的WCF-“ HTTP请求被客户端身份验证方案&#39;Anonymous&#39;禁止”错误 - IIS hosted WCF with SSL security -“The HTTP request was forbidden with client authentication scheme 'Anonymous'” error 添加WCF服务引用时,HTTP请求被禁止,客户端身份验证方案“匿名”错误 - The HTTP request was forbidden with client authentication scheme 'Anonymous' error, when adding WCF service reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM