WCF service method to return json or soap

前端 未结 1 952
孤城傲影
孤城傲影 2021-01-14 21:01

I have been reading lot of posts on retrieving/returning json objects in a WCF method. Correct me if I am wrong: Adding an endpoint and WebHTTp behavior in the config in add

相关标签:
1条回答
  • 2021-01-14 21:41

    Yes it is possible. JSON and SOAP need different bindings so your service needs two endpoints - one with webHttpBinding and webHttp endpoint behavior and second with basicHttpBinding or other SOAP oriented binding. These endpoints must have different relative addresses.

    If you want to support both JSON and XML (POX not SOAP) formats in REST service you can do it on the same endpoint in WCF 4 by defining automaticFormatSelectionEnabled="true" in the webHttp behavior used for the REST endpoint. This allows the endpoint to return the data formatted either as JSON or as XML. The choice of the format is based on the format of incoming request so a request in JSON will get a response in JSON and a request in XML will get a response in XML.

    0 讨论(0)
提交回复
热议问题