具有多个webHttpBinding绑定的WCF服务在visual studio测试客户端中失败

时间:2013-04-22 12:40:17

标签: wcf visual-studio-2012 wcf-4

我有一个定义了四个端点的服务,配置如下所示:

  <service name="Systembolaget.Services.ButikService" behaviorConfiguration="default">
    <endpoint
        address="xml"
        binding="webHttpBinding"
        behaviorConfiguration="xml"
        contract="Systembolaget.Contracts.Butiker.IButikService" />

    <endpoint
        address="json"
        binding="webHttpBinding"
        behaviorConfiguration="json"
        contract="Systembolaget.Contracts.Butiker.IButikService" />

    <endpoint
        address="soap"
        binding="basicHttpBinding"
        contract="Systembolaget.Contracts.Butiker.IButikService"
        bindingConfiguration="default"/>

    <endpoint
        address="mex"
        binding="mexHttpBinding"
        contract="IMetadataExchange" />
  </service>

<behaviors>
  <endpointBehaviors>
    <behavior name="xml">
      <webHttp defaultOutgoingResponseFormat="Xml" defaultBodyStyle="Bare"></webHttp>
    </behavior>

    <behavior name="json">
      <webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Bare"></webHttp>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="default">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

当使用任何端点的服务时,一切正常。但是,如果xml和json端点都存在,则无法在Visual Studio 2012中使用测试客户端。如果我注释掉一个或另一个,客户端工作,如果我在配置文件中保留两个,我会收到以下错误:

  

错误:无法从http://localhost:52832/VarugruppService.svc获取元数据如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用了元数据发布。有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455上的MSDN文档.WS-Metadata Exchange
  URI:http://localhost:52832/VarugruppService.svc
  元数据包含无法解析的引用:http://localhost:52832/VarugruppService.svc   在http://localhost:52832/VarugruppService.svc没有可以接受该消息的端点监听。这通常是由错误的地址或SOAP操作引起的。有关详细信息,请参阅InnerException(如果存在)   远程服务器返回错误:(404)Not Found.HTTP GET Error
  URI:http://localhost:52832/VarugruppService.svc
  下载“http://localhost:52832/VarugruppService.svc”时出错   请求失败,HTTP状态为404:Not Found。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您可以通过为每个webHttpBindng添加单独的绑定配置来实现此目的:

<bindings>
  <webHttpBinding>
    <binding name="xmlWebBinding">
    </binding>
    <binding name="jsonWebBinding">
    </binding>
  </webHttpBinding>

</bindings>
<services>
  <service name="Systembolaget.Services.ButikService" behaviorConfiguration="default">
    <endpoint
        address="xml"
        binding="webHttpBinding"
        bindingConfiguration="xmlWebBinding"
        behaviorConfiguration="xml"
        contract="Systembolaget.Contracts.Butiker.IButikService" />

    <endpoint
        address="json"
        binding="webHttpBinding"
        bindingConfiguration="jsonWebBinding"
        behaviorConfiguration="json"
        contract="Systembolaget.Contracts.Butiker.IButikService" />

    <endpoint
        address="soap"
        binding="basicHttpBinding"
        contract="Systembolaget.Contracts.Butiker.IButikService"
        bindingConfiguration="default"/>

    <endpoint
        address="mex"
        binding="mexHttpBinding"
        contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="xml">
      <webHttp defaultOutgoingResponseFormat="Xml" defaultBodyStyle="Bare"></webHttp>
    </behavior>

    <behavior name="json">
      <webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Bare"></webHttp>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="default">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

归功于本论坛底部的回答者:

http://tiku.io/questions/1554725/how-can-basichttpbinding-webhttpbinding-mexhttpbinding-endpoints-coexist-in-o