开发者

Two endpoints in WCF 3.5 for SOAP and JSON

I dont know what I am doing wrong. I have a WCF (.NET 3.5) service (JsonSoap.svc) that has two endpoints for soap and json content type. Both the endpoints refer to the same service. I am using only one Json endpoint in the client. My aim is to have the service method GetPerson() to return Json or soap depending on the endpoints used to connect to the service (hopefully this is possible in WCF?). I can see wsdl and was able to successfully ad the service reference in to the client side.

I get the following error after I make a call to the GetPerson() -

"An error occurred while receiving the HTTP response to http://localhost:80/JsonSoap/json/GetPerson. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details."

WCF service config

<!-- bindings -->
<bindings>

  <basicHttpBinding>
    <binding name ="soapBinding">
      <security mode="None">
      </security>
    </binding>
  </basicHttpBinding>

  <webHttpBinding>
    <binding name="webBinding">
    </binding>
  </webHttpBinding>
</bindings>

<!-- JSON behaviors -->
<endpointBehaviors>
  <behavior name="jsonBehavior">
    <enableWebScript  />
  </behavior>
</endpointBehaviors>
<serviceBehaviors>
  <behavior name="defaultBehavior">
    <serviceDebug includeExceptionDetailInFaults="true" />
    <serviceMetadata httpGetEnabled="true" />
  </behavior>
</serviceBehaviors>
</behaviors>
  <services>
    <service name="TestService.IJsonSoap" behaviorConfiguration="defaultBehavior">
      <host>
        <baseAddresses>
          <!-- note, choose an available port-->
          <add baseAddress="http://localhost:80/JsonSoap" />
        </baseAddresses>
  开发者_如何学Go    </host>

<endpoint address="soap" binding="basicHttpBinding"
          bindingConfiguration="soapBinding"
          contract="TestService.IJsonSoap" />

<endpoint address="json" binding="webHttpBinding"
          bindingConfiguration="webBinding"
          behaviorConfiguration="jsonBehavior"
          contract="TestService.IJsonSoap" />
</service>

WCF code:

[OperationContract]
[WebGet]
Person GetPerson(int ID);

WCF Client config:

<endpoint address="http://localhost:80/JsonSoap/json" binding="webHttpBinding"
          bindingConfiguration="webBinding" behaviorConfiguration="jsonBehavior"
          contract="MyService.IJsonSoap" />

Client code:

MyService.JsonSoapClient service = new JsonSoapClient();
MyService.Person person = service.GetPerson(10);


This will not work. WSDL servers only for SOAP services and it is the source for Add Service Reference in Visual Studio. You are using client code generated by Visual Studio but you are using it with Json endpoint which doesn't work.

Json endpoint represents REST service. To call WCF REST service in .NET you must either:

  • Build manully HTTP Request
  • Share service contract with a client and use ChannelFactory or WebChannelFactory to build a proxy
  • Use REST Starter KIT CTP2 and its HttpClient class (not recommended because development of REST Starter KIT ended).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜