History
I am basically a front end (android) developer and never had to create a web service Rather I was at the consuming end . Now this WCF business is overwhelming and I believe terribly complicated with a steep learning curve.
The Task
I need to make a simple SOAP service , hello world for the time being that would take an input XML , BUT RETURN JSON .
I am not sure why don't we have similar queries on the internet , kind of makes me wonder if it is not possible at all ?.
This is what I have so far .
Current Progress
My Contract
[ServiceContract]
public interface IHelloWorldService
{
[OperationContract]
String GetMessage(String name);
}
My Contract Impl
public string GetMessage(string name)
{
return "Hello World from " + name + "!";
}
My Service Config (in Web.Config. I have hosted this service in a asp.net website)
<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
I would be indeed indebted if you guys could point me to the correct direction. Also I am just 2 days old in this webservice coven , so I apologize for my naivety .
You can use a REST endpoint to return JSON.
SOAP relies exclusively on XML to provide messaging services, so if you really want/need to return JSON then you would need to wrap it in CDATA in the SOAP XML body. Unlike SOAP, however, REST does not have to use XML to provide the response, therefore you can output the data in other formats such as JSON.
SOAP web services are described using WSDL documents. JSON web services are structured less formally; they tend to be loosely coupled and prefer documentation by example. SOAP web services have an explicit error format involving SOAP Fault messages. There's no equivalent for JSON.
SOAP relies exclusively on XML to provide messaging services, so if you really want/need to return JSON then you would need to wrap it in CDATA in the SOAP XML body. Unlike SOAP, however, REST does not have to use XML to provide the response, therefore you can output the data in other formats such as JSON.
http://blog.smartbear.com/apis/understanding-soap-and-rest-basics/
You may want to consider using WCF
to provide a REST
-ful service rather than a SOAP
-based service.
https://msdn.microsoft.com/en-us/magazine/dd315413.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With