简体   繁体   中英

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. 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. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455 .WS-Metadata Exchange
URI: http://localhost:52832/VarugruppService.svc
Metadata contains a reference that cannot be resolved: http://localhost:52832/VarugruppService.svc .
There was no endpoint listening at http://localhost:52832/VarugruppService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.HTTP GET Error
URI: http://localhost:52832/VarugruppService.svc
There was an error downloading ' http://localhost:52832/VarugruppService.svc '.
The request failed with HTTP status 404: Not Found.

Any ideas?

You can achieve this by adding a separate binding configuration for each 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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