0

In this

post in answer was show that we can force service to return message in json. But wcf have feature that allows automatic convert return message in soap or rest format like json using few endpoints typed in config ? For example I set WebInvoke attribute on service and set two address for endpoint like serviceAddress/soap , serviceAddress/json and wcf choose good endpoint for specific format result?

Community
  • 1
  • 1
netmajor
  • 6,507
  • 14
  • 68
  • 100
  • 1
    SOAP vs. REST is one thing - returning JSON vs. XML is the other. There is no automatic switching between SOAP and REST - that depends on the **binding** for the endpoint you define. With REST (and only with REST, as far as I know), you can use the HTTP feature that allows "content negotiation", e.g. the request can tell the service what kind of format for the response (JSON or XML) it would like to have. – marc_s Sep 11 '11 at 21:20
  • So to support return SOAP or JSON I should create two service method - one with attribute [WebGet(ResponseFormat=WebMessageFormat.Json)] ,second without it to return SOAP ? – netmajor Sep 12 '11 at 06:23
  • 1
    You cannot "return SOAP" - it's not a data format! SOAP vs. REST is a question of how to **call** the service. Whether or not you use SOAP or REST is a decision you must make and thus you need to configure your bindings. You can use the HTTP mechanism to return **XML or JSON** from a REST service - yes. – marc_s Sep 12 '11 at 06:49
  • So I must use REST to return Json,ok. But also I have requirement to return SOAP structure of message (http://msdn.microsoft.com/en-us/library/aa226013(v=sql.80).aspx) Is is possible to use both on one service method or must on two ? – netmajor Sep 12 '11 at 07:50
  • 1
    You can definitely support both SOAP and REST at the same time by exposing two different endpoints - one with a SOAP binding (`basicHttpBinding`, `wsHttpBinding` etc.), and another with REST (`webHttpBinding`) – marc_s Sep 12 '11 at 07:51

0 Answers0