I understand that we can encode any object in xml and send the xml in post request over http.So What extra advantage did we have using soap and why it became popular.
Your question is very generic and broad, hence there could long discussion/debate on whether SOAP is popular, and its pros vs cons. Even not sure if its duplicate question.
I would like to answer it shortly.
Because SOAP is standard because accepted/published by W3.org, hence widely accepted, and XML RPC or just XML over HTTP is not, hence would be less acceptable to organizations/service providers/developers.
SOAP as per wiki
SOAP (originally Simple Object Access Protocol) is a messaging protocol specification for exchanging structured information in the implementation of web services in computer networks. Its purpose is to induce extensibility, neutrality and independence. It uses XML Information Set for its message format, and relies on application layer protocols, most often Hypertext Transfer Protocol (HTTP) or Simple Mail Transfer Protocol (SMTP), for message negotiation and transmission.
XML over HTTP as per wiki,
XML-RPC is a remote procedure call (RPC) protocol which uses XML to encode its calls and HTTP as a transport mechanism.1 "XML-RPC" also refers generically to the use of XML for remote procedure call, independently of the specific protocol. This article is about the protocol named "XML-RPC".
Hence, XML over HTTP is subset of SOAP.
Meaning, every SOAP transaction is also XML over HTTP/HTTPS, but every XML over HTTP/HTTPS can't be SOAP.
SOAP Example XML,
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Header>
...
</soap:Header>
<soap:Body>
...
<soap:Fault>
...
</soap:Fault>
</soap:Body>
</soap:Envelope>
XML over HTTP example:
<array>
<data>
<value><i4>1404</i4></value>
<value><string>Something here</string></value>
<value><i4>1</i4></value>
</data>
</array>
I would suggest you to do googling to more details, both are wide topics and I think can't be 100% in stack-overflow answer.
Related
I don't have something in particular that I need to implement, I am just trying to understand some concepts.
As far as I know, .NET web method (for example), that is inside a web service, is using the SOAP protocol. that means that the data received to the server needs to be in XML format, and the data that is returned from the web method should also be in XML format.
I know I can write something like this:
[WebMethod]
public static Object someMethod(Object josn)
{
Console.Write(json("someProperty"));
return new {name = "John"}
}
I know that data sent back to the client is in JSON format...
but if we are using the SOAP protocol, shouldn't it return XML?
I want to understand what is happening behind the scene or what am I missing, does the request was sent in xml format and the .NET framework knows how to extract the parameters that were sent, if so- how can I retrieve the full xml that represents the request made?
What you are referring to is called the SOAP envelope. Take a look here:
Sample SOAP Envelope
One of the easiest ways to see the SOAP envelope that is being used in a request or response is to use Fiddler or Postman.
EDIT
Here's an example of WCF SOAP envelope with JSON (not sure if you are using WCF or the old .NET Web Service with ASMX files):
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header></s:Header>
<s:Body>[{"DateOfBirth":"\/Date(286801200000+1300)\/","FirstName":"Foo","Id":1,"LastName":"Bar"},{"DateOfBirth":"\/Date(333720000000+1200)\/","FirstName":"Foo","Id":1,"LastName":"Bar"}]</s:Body>
</s:Envelope>
I am creating a WCF service and I am planning to set the message format as JSON. But when I use BasicHttpBinding, I get the response and request in XML format. I am not sure does that mean this WebMessageFormat.Json can be used only in WEBHttpBinding (REST)? I have an understanding that SOAP uses only XML but this MessageFormat attribute arise a question in me whether JSON format can be used across all binding.
When we try to call a web service using a java client (Axis) we are sending the method parameters fields in different order.
That is to say, if the WSDL order of the parameters is like;
<soap:Body>
<somemethod>
<messagetype>
**<x>int</x>**
<y>int</y>
</messagetype>
</somemethod>
</soap:Body>
and if we send them like
<soap:Body>
<somemethod>
<messagetype>
**<y>int</y>**
<x>int</x>
</messagetype>
</somemethod>
</soap:Body>
parameters are not filled in the ASPNET side. "x" and "y" stays as zeros ("0").
Any ideas if this is the standard?
Well, a SOAP request is just XML so my thoughts are that it's the SOAP implementation that would determine how parameters should match up.
But that varies from vendor to vendor. Some vendors may grab SOAP parameter values by element name (the proper way) and others may grab the values by node position (what you're probably running into).
Stick to the format specified by the WSDL and nobody gets hurt.
Has SOAP exclusively used HTTP POST historically? In other words, does SOAP mainly use HTTP POST for all types of request? In comparison, the RESTful approach may be to use request types closely matching the purpose of the message. I wondered what the current and historical stance has been for SOAP.
SOAP mainly considers the use of HTTP POST historically (though can use other protocols such as SMTP) for request and response since version 1.1. However, since version 1.2 it can use GET requests with no SOAP message receiving a SOAP response. (Papazoglou, Michael P. (2008). Web Services: Principles and Technology. Harlow: Pearson Education Limited. p140-143.)
I have a Flex application that needs to grab reporting data from a JasperReports Server, through the JasperReports Server Web Services API. Flex Builder 3 does a nice job of generating the web services consumption code, with one exception. If you ask for a directory list or an accounting of report parameters, JR Server returns plain XML in the SOAP wrapper and Flex parses it just fine. However, if you ask for a report itself, whether in XML or PDF format, it comes back as a multipart MIME message with some descriptive XML as the first part and the report -- even if the report itself is XML -- as the second part. Flex doesn't know what to do with multipart messages and just complains about invalid XML.
Here's a sample of the response. My current strategy is do some string parsing and manage the bits individually. But does Flex have any built-in methods to handle this? (I've been unable to find any.)
------=_Part_2_27050467.1235668849951
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <0F082AF1DAF83B3077B1867B4FC8AAA6>
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:runReportResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://axis2.ws.jasperserver.jaspersoft.com">
<runReportReturn xsi:type="xsd:string"><?xml version="1.0" encoding="UTF-8"?>\n<operationResult version="2.0.1">\n\t<returnCode><![CDATA[0]]></returnCode>\n</operationResult>\n
</runReportReturn>
</ns1:runReportResponse>
</soapenv:Body>
</soapenv:Envelope>
------=_Part_2_27050467.1235668849951
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-Id: <report>
%PDF-1.4\n%âãÏÓ\n1 0 obj <</Filter/FlateDecode/Length 29>>stream\nx+är\ná26S°00S\bIár\rá\näâ
What I am going to say is only what I believe:I may be wrong since I haven't tried this out.
I don't think you have much choice. Flex HTTPService (or whatever you are using) can offer only so many (/or so few) data formats. See here. For any custom stream you will have to retrieve it as an object and pass it through your own decoder. It appears that Flex does not do any parsing of the MIME message but depends on (which is also how browsers behave typically) the server to identify the content that is being transmitted. If the server only sends a text file but changes the content type to say audio/mpeg I think you will have the same problem. Even when Flex does know hot to handle text.
If you ever can get around to doing this experiment (with text files as MIME type video or whatever fancies you) do let us know.
Meanwhile, you can take a look at SerializationFilter and go on and add a new MIME type for PDF!
Hopefully, life will be a little easy with Flex 4 and the HTTPMultiService.