What is SOAP?

SOAP stands for Simple Object Access Protocol. It is an XML based lightweight protocol, which allows software components and application components to communicate, mostly using HTTP (can use SMTP etc). SOAP sits on top of the HTTP protocol. SOAP is nothing but XML message based document with pre-defined format. SOAP is designed to communicate via the Internet in a platform and language neutral manner and allows you to get around firewalls as well. 

Let’s look at the structure of a SOAP messages:

  • A SOAP message MUST be encoded using XML
  • A SOAP message MUST use the SOAP Envelope namespace
  • A SOAP message MUST use the SOAP Encoding namespace
  • A SOAP message must NOT contain a DTD reference
  • A SOAP message must NOT contain XML Processing Instructions

 

<?xml version="1.0"?>

<soap:Envelope

xmlns:soap="http://www.w3.org/2001/12/soap-envelope"

soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Header>

...

...

</soap:Header>

<soap:Body>

...

...

<soap:Fault>

...

...

</soap:Fault>

</soap:Body>

</soap:Envelope>

 

Let’s look at a SOAP request and a SOAP response:

SOAP Request:

POST /Price HTTP/1.1

Host: www.tuturself.com

Content-Type: application/soap+xml; charset=utf-8

Content-Length: 300

<?xml version="1.0"?>

<soap:Envelope

xmlns:soap="http://www.w3.org/2001/12/soap-envelope"

soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body>

<m:GetPrice xmlns:m="http://www.tuturself.com/prices">

<m:Item>Java Services</m:Item>

</m:GetPrice>

</soap:Body>

</soap:Envelope>

 

SOAP Response:

HTTP/1.1 200 OK

Content-Type: application/soap; charset=utf-8

Content-Length: 200

<?xml version="1.0"?>

<soap:Envelope

xmlns:soap="http://www.w3.org/2001/12/soap-envelope"

soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body>

<m:GetPriceResponse

xmlns:m="http://www.tuturself.com/prices">

<m:Price>3500.00</m:Price>

</m:GetPriceResponse>

</soap:Body>

</soap:Envelope>

 

Let’s look at a HTTP header containing a soap message:

POST /Price HTTP/1.1

Host: www.tuturself.com

Content-Type: application/soap+xml; charset=utf-8

Content-Length: 200

 

J2EE