Can a WCF SOAP service return JSON as output?

History


I am mainly an interface developer (android) and should never have created a web service. Rather, I was at the end of consumption. Now this WCF business is stunning and I find it terribly difficult with a steep learning curve.

Task


I need to make a simple SOAP service, an evil world at the moment, that will accept input XML, BUT RETURN JSON.

I’m not sure why we don’t have such requests on the Internet, and this makes me wonder if this is possible at all?

This is what I still have.

Current progress


My contract

[ServiceContract] public interface IHelloWorldService { [OperationContract] String GetMessage(String name); } 

My contract is Impl

 public string GetMessage(string name) { return "Hello World from " + name + "!"; } 

My Service Config (at Web.Config. I posted this service on asp.net)

 <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="MyServiceTypeBehaviors"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="WebBehavior"> <webHttp defaultOutgoingResponseFormat="Json" /> </behavior> </endpointBehaviors> </behaviors> <services> <service name="MyWcfServices.HelloWorldService" behaviorConfiguration="MyServiceTypeBehaviors"> <endpoint address="" binding="wsHttpBinding" behaviorConfiguration="WebBehavior" contract="MyWcfServices.IHelloWorldService"/> <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/> </service> </services> </system.serviceModel> 

Questions


  • Is SOAP closely related to XML? So you can not send JSON as output?
  • Is it true that to send JSON as output, you need to go to the REST paradigm?
  • Do I get XML every time because I use WCFStorm scripts with HTTP headers and send the default mime XML type?
  • How can I check the WCF service that returns JSON? Do I have any test client for this? I downloaded the Chrome extension called Wizdler, but for some reason it only works with the "basicHttpBinding" binding. I was told that I cannot use this binding if I want to make a SOAP service.

I really would have been obligated if you guys could point me in the right direction. Also, I only have 2 days in this web service, so I apologize for my naivety.

+6
source share
1 answer

SOAP relies solely on XML to provide messaging services, so if you really need / need to return JSON, you will need to wrap it in CDATA in a SOAP XML document. However, unlike SOAP, REST should not use XML to respond, so you can output data in other formats, such as JSON.

http://blog.smartbear.com/apis/understanding-soap-and-rest-basics/

You might want to use WCF to provide a REST -ful service, rather than a SOAP based service.

https://msdn.microsoft.com/en-us/magazine/dd315413.aspx

+5
source

Source: https://habr.com/ru/post/982070/


All Articles