【问题标题】:WCF service with multiple webHttpBinding bindings fails in visual studio test client具有多个 webHttpBinding 绑定的 WCF 服务在 Visual Studio 测试客户端中失败
【发布时间】:2013-04-15 08:52:19
【问题描述】:

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

  <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.WS-Metadata Exchange
的 MSDN 文档 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:未找到。

有什么想法吗?

【问题讨论】:

  • 是的 - WCF 测试客户端仅适用于 SOAP 绑定 - webHttpBinding 的任何内容。基于REST的webHttpBinding可以直接用浏览器测试,也可以用FIddler之类的工具测试
  • 是的,我知道,而且我确实有一个可以工作的肥皂绑定,只要我没有为服务定义多个 webHttpBinding。

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


【解决方案1】:

您可以通过为每个 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-14
    相关资源
    最近更新 更多