SOAP stands for Simple Object Access Protocol and is used for communication between applications through the Internet. SOAP is a platform and language independent. It also allows applications to communicate between each other though both applications are on different operating systems. SOAP messages are typically written using XML.
Here is an example of SOAP syntax:
<?xml version=”1.0″?>
<soap:Envelope>
<soap:Header>
xmlns:soap=”http://www…./soap-envelope”
soap:encodingStyle=”http://www…./soap-encoding”>
…
…
</soap:Header>
<soap:Body>
…
…
<soap:Fault>
…
…
</soap:Fault>
</soap:Body>
</soap:Envelope>
SOAP Envelope element is a root element and it defines the XMLdocument.
xmlns:soap namespace defines the Envelope as a SOAP Envelope.
The encodingStyle attribute is used to define which data types are used in the document.
SOAP has header element which is optional and contains the information about the application.
Body element contains actual SOAP Messages.
Fault element is used to indicate errors. Let us see each of them in detail:
<faultcode> :- A code which is used for identifying tags.
<faultstring>:- Explanation of the fault.
<faultactor>:- Whom fault was caused by.
<detail>:- Further details about the fault.
Using a TCP connection, communication is formed between HTTP client and server. Once the connection is made the following messages are passed from client to server.
POST /item HTTP/1.1
Host: 189.121.356.314
Content-Type: text/plain
Content-Length: 200
If connection is successful then the following messages are returned by the server.
200 OK
Content-Type: text/plain
Content-Length: 200
SOAP connection means connection between HTTP and XML.The request can be HTTP POST or HTTPGET.In the example below, a GetempSalary request is sent to a server. The request has a empName parameter, and a salary parameter will be returned in the response. The namespace for the function is defined in “http://www.employee.org/salary” address.
The SOAP request:
POST /salary HTTP/1.1
Host: www.employee.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: mmm
<?xml version=”1.0″?>
<soap:Envelope
xmlns:soap =”http://www.abc.org/soap-envelope”
soap:encodingStyle =”http://www.abc.org/soap-encoding”>
<soap:Body xmlns:r =”http://www.employee.org/salary”>
<r:Getempsalary>
<r:empName>John</r:empName>
</r:Getempsalary>
</soap:Body></soap:Envelope>
A SOAP response:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: mmm<?xml version=”1.0″?>
<soap:Envelope
xmlns:soap =”http://www.abc.org/soap-envelope”
soap:encodingStyle =”http://www.abc.org/soap-encoding”>
<soap:Body xmlns:r =”http://www.employee.org/salary”>
<r:GetempsalaryResponse>
<r:salary>20000</r:salary>
</r:GetempsalaryResponse>
</soap:Body></soap:Envelope>
If you enjoyed this post, make sure you subscribe to my RSS feed!
Tags: Code, Programming, Simple Object Access Protocol, SOAP, XML
