1

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

  <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
URI 的 MSDN 文档: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 状态为 404:未找到。

有任何想法吗?

4

1 回答 1

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

于 2015-01-14T12:54:16.480 回答