SOAP is a simple XML-based protocol that allows applications to exchange information over HTTP.
Or, more simply, SOAP is the protocol used to access network services.
What is SOAP?
- SOAP refers to Simple Object Access Protocol
- SOAP is a communication protocol.
- SOAP is used for communication between applications.
- SOAP is a format used to send messages.
- SOAP is designed for communication over the Internet
- SOAP is independent from the platform
- SOAP is independent of Language
- SOAP Based on XML
- SOAP is simple and scalable
- SOAP allows you to bypass the Firewall
- SOAP will be developed as W3C Standard
Why SOAP?
For application development, it is very important to enable Internet communication between applications.
Currently, applications use Remote Procedure Call (RPC) to communicate with objects such as DCOM and CORBA, but HTTP is not designed for this purpose. RPC may cause compatibility and Security Issues. firewalls and proxy servers usually block such traffic.
It is a better way to communicate between applications through HTTP, because HTTP is supported by all Internet browsers and servers. SOAP is created to complete this task. SOAP provides a standard method that allows applications running on different operating systems and using different technologies and programming languages to communicate with each other.
Microsoft and SOAP
SOAP is a key element of Microsoft. net architecture and is used for future Internet application development.
SOAP 1.1 is submitted to W3C
In March May 2000, UserLand, Arba, Commerce One, Compaq, Developmentor, HP, IBM, IONA, Lotus, Microsoft, and SAP submitted the SOAP Internet Protocol to W3C, these companies expect this Protocol to completely change application development by connecting graphic user interface desktop applications to powerful Internet servers using Internet standards (HTTP and XML.
W3C is developing SOAP 1.2.
The first draft of public work on SOAP was published by W3C in December 2001. For more information about SOAP activities in W3C, visit our W3C tutorial.
SOAP build Module
A soap message is a common XML document that contains the following elements:
- The required Envelope element. This XML document can be identified as a SOAP message.
- Optional Header elements, including Header information
- Required Body elements, including all call and response information
- An optional Fault element that provides information about errors that occur when processing the message.
All the above elements are declared in the default namespace for SOAP encapsulation:
Http://www.w3.org/2001/12/soap-envelope
And the default namespace for SOAP encoding and data types:
Http://www.w3.org/2001/12/soap-encoding
Syntax Rules
Here are some important syntax rules:
- SOAP messages must be encoded in XML.
- SOAP messages must use the SOAP Envelope namespace
- SOAP messages must use the SOAP Encoding namespace
- SOAP messages cannot contain DTD references
- SOAP messages cannot contain XML processing instructions
Basic Structure of SOAP messages
<?xml version="1.0"?><soap:Envelopexmlns: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>
The Envelope element of the forced SOAP is the root element of the SOAP message.
SOAP Envelope elementThe required SOAP Envelope element is the root element of the SOAP message. It defines an XML document as a SOAP message.
Note xmlns: Use of the soap namespace. Its value should always be:
http://www.w3.org/2001/12/soap-envelope
And it can define encapsulation as SOAP encapsulation:
<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> ... Message information goes here ...</soap:Envelope>
Xmlns: soap namespaceSOAP messages must have an Envelope associated with the namespace "http://www.w3.org/2001/12/soap-envelope"
Element.
If different namespaces are used, an error occurs in the application and the message is discarded.
EncodingStyle attributesThe encodingStyle attribute of SOAP is used to define the data type used in the document. This attribute can appear in any SOAP
And will be applied to the content of the element and all child elements of the element. No default encoding method is available for SOAP messages.
Syntaxsoap:encodingStyle="URI"
Instance<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">...Message information goes here...</soap:Envelope>
The optional SOAP Header element contains Header information.
SOAP Header elementOptional SOAP Header elements can contain application-specific information (such as authentication and payment) about SOAP messages ). If the Header element is provided, it must be the first child element of the Envelope element.
Note: The direct sub-elements of all Header elements must be qualified namespaces.
<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Header><m:Transxmlns:m="http://www.w3schools.com/transaction/"soap:mustUnderstand="1">234</m:Trans></soap:Header>......</soap:Envelope>
The preceding example contains a header with a "Trans" element. Its value is 234. The value of the "mustUnderstand" attribute of this element is "1 ".
SOAP in the default namespace ("http://www.w3.org/2001/12/soap-envelope ")
Three attributes are defined. These three attributes are: actor, mustUnderstand, and encodingStyle. The attributes defined in the SOAP header can define how the container
Process the SOAP message.
Actor attributesBy passing through different endpoints along the message path, SOAP messages can be transmitted from a sender to a receiver. Not all parts of the SOAP message are intended to be transmitted to the SOAP
The final endpoint of the message. However, in another aspect, it may be intended to be sent to one or more endpoints on the message path.
The actor attribute of SOAP can be used to address the Header element to a specific endpoint.
Syntaxsoap:actor="URI"
Instance<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Header><m:Transxmlns:m="http://www.w3schools.com/transaction/"soap:actor="http://www.w3schools.com/appml/">234</m:Trans></soap:Header>......</soap:Envelope>
MustUnderstand attributesThe mustUnderstand attribute of SOAP can be used to identify whether a title item is mandatory or optional for the recipient to process it.
If you add a child element to the Header element
"MustUnderstand =" 1 "indicates that the recipient processing this header must recognize this element. If the recipient cannot recognize this element, it must be invalid when processing this header.
Syntaxsoap:mustUnderstand="0|1"
Instance<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Header><m:Transxmlns:m="http://www.w3schools.com/transaction/"soap:mustUnderstand="1">234</m:Trans></soap:Header>......</soap:Envelope>
EncodingStyle attributesThe encodingStyle attribute of SOAP has been explained in the previous section.
The forced SOAP Body element contains the actual SOAP message.
SOAP Body ElementThe required SOAP Body element can contain the actual SOAP message to be sent to the Message endpoint.
The direct sub-element of the SOAP Body element can be a qualified namespace. SOAP
In the default namespace ("http://www.w3.org/2001/12/soap-envelope"), an element inside the Body element is defined. That is, the SOAP
Fault Element, used to indicate error messages.
<?xml version="1.0"?><soap:Envelopexmlns: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.w3schools.com/prices"> <m:Item>Apples</m:Item> </m:GetPrice></soap:Body></soap:Envelope>
The above example requests the price of apple. Note that the above m: GetPrice and Item elements are application-specific elements. They are not part of the SOAP standard.
A soap response should be similar to the following:
<?xml version="1.0"?><soap:Envelopexmlns: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.w3schools.com/prices"> <m:Price>1.90</m:Price> </m:GetPriceResponse></soap:Body></soap:Envelope>