简体   繁体   English

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

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

I have a service with four endpoints defined, the configuration looks like this: 我有一个定义了四个端点的服务,其配置如下所示:

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

When using the service with any of the end points it all works fine. 将服务与任何端点一起使用时,一切正常。 However I can't use the test client in Visual Studio 2012 if both the xml and the json end point exists. 但是,如果同时存在xml和json端点,则无法在Visual Studio 2012中使用测试客户端。 If I comment out one or the other, the client works, if I keep both in the config file I get the following error: 如果我注释掉其中一个,则客户端可以工作,如果将两者都保留在配置文件中,则会出现以下错误:

Error: Cannot obtain Metadata from http://localhost:52832/VarugruppService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. 错误:无法从http://localhost:52832/VarugruppService.svc获取元数据。如果这是您有权访问的Windows(R)Communication Foundation服务,请检查是否已在指定地址启用元数据发布。 For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455 .WS-Metadata Exchange 有关启用元数据发布的帮助,请参阅MSDN文档, http://go.microsoft.com/fwlink/?LinkId=65455http://go.microsoft.com/fwlink/?LinkId=65455
URI: http://localhost:52832/VarugruppService.svc URI: http://localhost:52832/VarugruppService.svc
Metadata contains a reference that cannot be resolved: http://localhost:52832/VarugruppService.svc . 元数据包含无法解析的引用: http://localhost:52832/VarugruppService.svc
There was no endpoint listening at http://localhost:52832/VarugruppService.svc that could accept the message. http://localhost:52832/VarugruppService.svc上没有侦听终结点的端点可以接受该消息。 This is often caused by an incorrect address or SOAP action. 这通常是由不正确的地址或SOAP操作引起的。 See InnerException, if present, for more details. 有关更多详细信息,请参见InnerException(如果存在)。
The remote server returned an error: (404) Not Found.HTTP GET Error 远程服务器返回错误:(404)找不到HTTP GET错误
URI: http://localhost:52832/VarugruppService.svc URI: http://localhost:52832/VarugruppService.svc
There was an error downloading ' http://localhost:52832/VarugruppService.svc '. 下载“ http://localhost:52832/VarugruppService.svc ”时http://localhost:52832/VarugruppService.svc
The request failed with HTTP status 404: Not Found. 请求失败,HTTP状态为404:找不到。

Any ideas? 有任何想法吗?

You can achieve this by adding a separate binding configuration for each webHttpBindng: 您可以通过为每个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>

Credit to the answerer at the bottom of this forum: 归功于该论坛底部的回答者:

http://tiku.io/questions/1554725/how-can-basichttpbinding-webhttpbinding-mexhttpbinding-endpoints-coexist-in-o 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