错误[否协议绑定指定的地址...&QUOT匹配;绑定、协议、错误、地址

2023-09-03 02:08:59 作者:前面逗比回头说我好帅@

我已经托管在IIS服务器2 WCF serivces。

I have 2 WCF serivces hosted in IIS server.

下面是web.config中

Here is 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>

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

When I try to run it I got

没有协议绑定匹配给定   地址   HTTP://本地主机:9001 / BubensService。   协议绑定是在配置   在IIS站点级别或WAS   配置。

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服务,在服务端点定义你的地址是不是你需要使用一个。

When you host your WCF services in IIS, your address defined in the service endpoints is not the one you need to use.

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

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

Rather, the web server, its port (usually 80) and the virtual directory plus the SVC file determine your service address. So you service addresses here would be:

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

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

What you can do is define relative addresses, e.g.:

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

那么这个服务将可以被调用为​​:

Then this service would be callable at :

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