【问题标题】:error "No protocol binding matches the given address ..."错误“没有协议绑定与给定地址匹配......”
【发布时间】:2010-11-23 21:34:01
【问题描述】:

我在 IIS 服务器中托管了 2 个 WCF 服务。

这里是 web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="HttpBinding" />
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="BShop.Services.BubensService">
        <endpoint address="http://localhost:9001/BubensService" binding="basicHttpBinding"
          bindingConfiguration="HttpBinding" name="" contract="BShop.Services.IBubensService" />
      </service>
      <service name="BShop.Services.OrdersService">
        <endpoint address="http://localhost:9001/OrdersService" binding="basicHttpBinding"
          bindingConfiguration="HttpBinding" contract="BShop.Services.IOrdersService" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

当我尝试运行它时,我得到了

没有与给定的协议绑定匹配 地址 'http://localhost:9001/BubensService'。 协议绑定配置在 IIS 或 WAS 中的站点级别 配置。

我在配置中遗漏了什么?

【问题讨论】:

    标签: .net wcf


    【解决方案1】:

    当您在 IIS 中托管 WCF 服务时,您在服务端点中定义的地址不是您需要使用的地址。

    <endpoint 
          // this is **NOT** the address you can use to call your service! 
          address="http://localhost:9001/BubensService"
    

    相反,Web 服务器、其端口(通常为 80)和虚拟目录加上 SVC 文件决定了您的服务地址。所以你这里的服务地址是:

    http://YourServer/YourVirtualDirectory/YourServiceFile.svc/
    

    你可以做的是定义相对地址,例如:

    <service name="BShop.Services.BubensService">
       <endpoint name="" 
                 address="BubensService" 
                 binding="basicHttpBinding" bindingConfiguration="HttpBinding"  
                 contract="BShop.Services.IBubensService" />
    </service>
    

    那么这个服务可以在以下位置调用:

    http://YourServer/YourVirtualDirectory/YourServiceFile.svc/BubensService
    

    【讨论】:

    • 在端点中定义地址和如果我们定义一个baseurl有什么区别? 2个基本网址,1个服务器定位其他本地主机解决问题吗?
    【解决方案2】:

    只是为了人们搜索的利益。我遇到了这个问题。为了解决这个问题,我使用marc_s 的答案查看了 web.config,然后做了以下操作,因为我仍然遇到问题:

    1. 删除虚拟目录。
    2. 进入项目属性 -> Web 面板 -> 选择“使用本地 IIS Web 服务器”,项目 URL 为 http://{localhost}/{myservice}(显然没有大括号)并重新创建虚拟目录。
    3. 将应用程序池更改为具有集成管道模式的 .NET 4。应用程序池更改似乎解决了这个问题。

    【讨论】:

      【解决方案3】:

      注意如果有人在使用 Visual Studio 开发期间在浏览器中查看 WCF 服务时遇到此问题,那么此问题适合他们。

      在为Web.config 文件中的端点address 属性分配值后尝试从VS 查看我的.svc 服务时遇到了这个问题,但是如果我没有为端点address 属性分配值然后它完美地工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-07
        • 1970-01-01
        • 2013-09-24
        • 1970-01-01
        • 1970-01-01
        • 2016-09-07
        • 2017-08-13
        • 2012-12-03
        相关资源
        最近更新 更多