.net - 错误 "No protocol binding matches the given address ..."

标签 .net wcf

我在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>

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

No protocol binding matches the given address 'http://localhost:9001/BubensService'. Protocol bindings are configured at the Site level in IIS or WAS configuration.



我在配置中错过了什么?

最佳答案

当您在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

关于.net - 错误 "No protocol binding matches the given address ...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4261180/

相关文章:

c# - 从 .Net 连接到 AS400

c# - 将属性作为参数的通用函数

asp.net - 如何让服务从 global.asax 启动而无需调用它?

c# - 在 String.Format 中转义大括号 '{'

c# - Bloomberg .Net API - 多种证券的响应数据

.net - 在 OO 中建模的一对一关系

multithreading - .NET 4.5 增加 WCF 客户端调用异步?

asp.net-mvc - 在 .NET 中实现基于 REST 的 Web 服务的最佳方法是什么?

c# - wcf新手问题: arrays as properties

c# - "Add Service Reference"到底做了什么?