What is soap in web services

What is SOAP?

“Simple Object Access Protocol” – a lightweight XML-based messaging protocol used to encode the information in Web service request and response messages before sending them over a network. It is used to send XML from one server to another via HTTP. The best part about SOAP is that it is universal and secure. SOAP messages are independent of any operating system or protocol and may be transported using a variety of Internet protocols, including SMTP, MIME, and HTTP. In order to fully understand SOAP, you will need to know about markup languages, namespaces .

SOAP Versions:

In July 2001, the XML Protocol Working Group released a “working draft” of SOAP 1.2. Within the W3C, this document is officially a work in progress, meaning that the document is likely to be updated many times before it is finalized.

SOAP Version 1.1 is available online at

http://www.w3.org/TR/SOAP/

The working draft of SOAP Version 1.2 is available at

http://www.w3.org/TR/soap12/

A SOAP message is an XML document containing the following elements.

Envelope: ( Mandatory )
Defines the start and the end of the message.

Header: ( Optional )
Contains any optional attributes of the message used in processing the message, either at an intermediary point or at the ultimate end point.

Body: ( Mandatory )
Contains the XML data comprising the message being sent.

Fault: ( Optional )
An optional Fault element that provides information about errors that occurred while processing the message

SOAP Envelope Element:

The required SOAP Envelope element is the root element of a SOAP message. This element defines the XML document as a SOAP message.
Example

The xmlns:soap Namespace

Notice the xmlns:soap namespace in the example above. It should always have the value of: “http://www.w3.org/2001/12/soap-envelope”.

The namespace defines the Envelope as a SOAP Envelope.

If a different namespace is used, the application generates an error and discards the message.
The encodingStyle Attribute

The encodingStyle attribute is used to define the data types used in the document. This attribute may appear on any SOAP element, and applies to the element’s contents and all child elements.

SOAP Header Element:

The optional SOAP Header element contains application-specific information (like authentication, payment, etc) about the SOAP message.

If the Header element is present, it must be the first child element of the Envelope element.

Note: All immediate child elements of the Header element must be namespace-qualified.

The example above contains a header with a “Trans” element, a “mustUnderstand” attribute with a value of 1, and a value of 555.
The SOAP mustUnderstand attribute can be used to indicate whether a header entry is mandatory or optional for the recipient to process.

SOAP Body Element:

The required SOAP Body element contains the actual SOAP message intended for the ultimate endpoint of the message.

Immediate child elements of the SOAP Body element may be namespace-qualified.
Example

SOAP Fault Element:

The optional SOAP Fault element is used to indicate error messages.

If a Fault element is present, it must appear as a child element of the Body element. A Fault element can only appear once in a SOAP message.

The SOAP Fault element has the following sub elements:

SOAP Example

In the example below, a GetStockPrice request is sent to a server. The request has a StockName parameter, and a Price parameter that will be returned in the response. The namespace for the function is defined in “http://www.gopaldas.org/stock”.

A SOAP request:

POST /InStock HTTP/1.1
Host: www.gopaldas.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

The SOAP response:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

Gopal Das
Follow me

Gopal Das

Founder at GopalDas.Org
He is a technology evangelist, Salesforce trainer, blogger, and working as a Salesforce Technical Lead. After working in Java based project implementation, he jumped to the Salesforce system on a whim and never looked back. He fell in love with Salesforce’s flexibility, scalability, and power. He expanded his knowledge of the platform and became a Certified App Builder, Administrator, Platform Developer I, SalesCloud Consultant while leading the Salesforce implementation and technology needs. He has worked in a wide variety of applications/services like desktop, web and mobile applications.
Gopal Das
Follow me

Leave a Reply

Your email address will not be published. Required fields are marked *