Soap webservice request vs HTTP POST request?

21,774

Solution 1

Your assumptions are generally correct. Yet, the subtelties can lead to huge differences.

Claim 1 : both are HTTP.

SOAP is generally used with an HTTP "binding". Yet it does not have to be that way. SOAP is designed to be fairly transport agnostic. It is not uncommon to have SOAP being used over JMS (although one might consider this an overuse of JMS, and an over architected protocol), it is certainly in production in many places. Rarely seen are SOAP/SMTP or SOAP/TCP without HTTP, but these exist too.

Webservice is a also post request which contains soap envelope as request body

A SOAP call over HTTP is a POST request. It may not be of content-type xml, though, as some variants such as SwA (SOAP with attachments) or XOP+MTOM variants may produce HTTP payloads that are MIME/Multipart (the first part of which is the SOAP Enveloppe in its pure XML form).
This use cas is most common when on is to send large binary content over a SOAP Call, and for which binary encoding may add a large weight to the request (base64 is a 1.3x factor in weight).

java Stub internally marshal the XML, creates HTTP request and send it to consumer

That is the usual way it is done, Axis framework and JAXWS frameworks work primarily this way.

The older SAAJ API, a standard EE API, requires you to build your SOAP Message by hand, using the DOM APIs, (see SOAPMessageFactory), and then send it.

If you look at Spring WS, you'll have something close to your claim, but where each part is fairly exposed and in your control (you may elect to build certain calls with a DOM Api, others by using JAXB marshalling, ...).

3)Servlet at consumer side intercpets that request and unrmashal it to java object and send it to corresponding service

Again, this is how things generaly work. But you can also have an implementation that works outside a servlet container. (See Endpoint Service API in JAX WS).

Solution 2

Your assumptions are right:-

Yes, Servlet request and Web service request both are normal HTTP request and yes, SOAP web service internally use HTTP POST.

Yes,java internally marshal the XML. Also, at client end one java web service client(may be a wrapped in servlet) un-marshal it. A SOAP message or SOAP type web service has many characteristics like:-

  • SOAP message mostly send data using XML format. XMLs are technology independent. So, SOAP can interact with two heterogeneous web applications built in two separate technologies and exchange data using XML.
  • SOAP web services send XML using HTTP protocol. Data are sent wrapped in an XML using the payload of HTTP.
  • SOAP web services can be secured. For an example, all the payment related transactions using credit card and bank info are done using secured SOAP web services.
  • A SOAP web service accepts XML in request and returns XML in response. In case of errors this return XMLs can also contain SOAP faults. SOAP faults contain the description of error and an error code.
  • Web services can carry attachment document also like PDF, Word etc. with its XML payload. Java provides separate API for this type of web services. There is an API available in java called SAAJ to accomplish this.
Share:
21,774
emilly
Author by

emilly

merge with [http://stackoverflow.com/users/1823678/emilly ]

Updated on August 28, 2020

Comments

  • emilly
    emilly over 3 years

    I am coming from servlet/web application world and started learning web services(SOAP based). I have gone through some of the webservice tutorials. I am trying to draw the parallel between normal http request and webservice request. Here are my observations ;-

    1)Both are HTTP request. Webservice is a also post request which contains soap envelope as request body. Soap envelope is just a normal xml which contains the data

    2)java Stub internally marshal the XML , creates HTTP request and send it to consumer

    3)Servlet at consumer side intercpets that request and unrmashal it to java object and send it to corresponding service.

    Is my observation correct ? I know there may be other complexities but i tried to put the comparison in simple manner.