繁体   English   中英

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

[英]WCF service with multiple webHttpBinding bindings fails in visual studio test client

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

  <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服务,请检查是否已在指定地址启用元数据发布。 有关启用元数据发布的帮助,请参阅MSDN文档, http://go.microsoft.com/fwlink/?LinkId=65455http://go.microsoft.com/fwlink/?LinkId=65455
URI: http://localhost:52832/VarugruppService.svc
元数据包含无法解析的引用: http://localhost:52832/VarugruppService.svc
http://localhost:52832/VarugruppService.svc上没有侦听终结点的端点可以接受该消息。 这通常是由不正确的地址或SOAP操作引起的。 有关更多详细信息,请参见InnerException(如果存在)。
远程服务器返回错误:(404)找不到HTTP GET错误
URI: http://localhost:52832/VarugruppService.svc
下载“ http://localhost:52832/VarugruppService.svc ”时http://localhost:52832/VarugruppService.svc
请求失败,HTTP状态为404:找不到。

有任何想法吗?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM