SOAP (Simple Object access Protoco) is a simple protocol for exchanging information in a decentralized or distributed environment, and is an XML-based protocol. This protocol specification was jointly presented by IBM, Microsoft, Userland and DevelopMentor in 1998 and supported by IBM, Lotus, Compaq and other companies, and was presented to the World Wide Web Consortium in 2000 Wide Web consortium;w3c). The SOAP protocol specification is now maintained by the XML workgroup of the World Wide Web Consortium. SOAP version 1.2 became the recommended version on June 24, 2003.
The SOAP protocol includes the following four-part content:
In SOAP encapsulation (envelop), encapsulation defines a framework that describes what the content in a message is, who sent it, who should accept it and deal with it, and how to deal with it.
SOAP Encoding Rules (encoding rules), which defines the type of data that needs to be used when exchanging information between different applications;
A SOAP RPC representation (RPC representation) that defines a contract that represents a remote procedure call and answer;
- A SOAP binding (binding) that defines the contract that SOAP uses to exchange information using the underlying protocol. The use of the HTTP/TCP/UDP protocol is possible;
The relationship between four parts
SOAP messages are essentially unidirectional transmissions from the sending end to the receiving end, but they are often combined to perform a pattern similar to request/reply. All SOAP messages are encoded using XML. A SOAP message is an XML document that contains the package with a required soap, an optional SOAP header (header), and a required SOAP body block (body).
Binding soap to HTTP provides features that take advantage of both the style and dispersion of soap, as well as the rich feature Library of HTTP. Transmitting SOAP over HTTP does not mean that soap overwrites existing HTTP semantics, but that the soap semantics on HTTP are naturally mapped to HTTP semantics. In situations where HTTP is used as a protocol binding, RPC requests are mapped to HTTP requests, while RPC responses are mapped to HTTP replies. However, using SOAP on RPC is not limited to HTTP protocol bindings. Soap can also be bound to TCP and UDP protocols.
Although these four parts are defined as a whole as part of SOAP, they are functionally intersecting and independent of each other. In particular, envelopes (envelop) and coding rules (encoding) are defined in different XML namespaces, which makes the definition simpler.
Grammar rules
SOAP messages must be encoded in XML;
SOAP messages must use the SOAP Envelope namespace;
SOAP messages must use the SOAP Encoding namespace;
A SOAP message cannot contain a DTD reference;
SOAP messages cannot contain XML processing instructions;
SOAP Message Format
The format of the SOAP message is relatively simple, such as:
The following is the basic format of a SOAP message:
<?XML version= "1.0" encoding= "Utf-8"?><Soap:envelopeXmlns:soap= "Http://www.w3.org/2003/05/soap-envelope"Soap:encodingstyle= "Http://www.w3.org/2003/05/soap-encoding"> <Soap:header> <!--message header, optional - </Soap:header> <Soap:body> <!--message content, required - <Soap:fault> <!--error message, optional - </Soap:fault> </Soap:body></Soap:envelope>
A SOAP message is an ordinary XML document that contains the following elements:
A required Envelope element, whereby the XML document can be identified as a SOAP message;
The optional header element, which contains header information, is generally used for authentication;
The required Body element, which contains all the invocation and response information;
An optional Fault element that provides descriptive information about the error that occurred while processing this message;
Syntax rules detailed soap Envelope
Envelope
is the primary container for the SOAP message structure and the root element of the SOAP message, which must appear in each SOAP message to mark the XML document as a SOAP message.
In soap, you use namespaces to differentiate a SOAP message element from an application-defined element, limiting the scope of a SOAP message element to a specific region.
< Soap:envelope Xmlns:soap = "http://schemas.xmlsoap.org/soap/envelope/" soap:encodingstyle= "http://www.w3.org/2003/05/soap-encoding"></ Soap:envelope >
The properties encodingStyle
of SOAP are used to define the type of data used in the document. This property can appear in any SOAP element and is applied to the contents of the element and to all child elements of the element.
SOAP Header
This is optional, and if you need to Header
Add an element, it must Envelope
be the first child element. Header
You can also include 0 or more optional child elements, called header items, and all header items are generally part of a particular interface-related namespace.
<Soap:envelopeXmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/"Soap:encodingstyle= "Http://www.w3.org/2003/05/soap-encoding"> <Soap:header> <Authenheaderxmlns= "http://www.example.com"> <sauthenticate>String</sauthenticate> </Authenheader> </Soap:header> <Soap:body> </Soap:body></Soap:envelope>
Header
element is used to transmit some additional messages, such as authentication information, along with the message.
SOAP Body
The elements of Body
a SOAP message can contain any of the following elements:
The remote Procedure call (RPC) method and its parameters;
The data required by the target application (the message receiver is the interface caller);
SOAP Fault that report faults and status messages;
The Body
immediate child elements of all elements are called body items, and all body items are typically namespaces that belong to a particular feature.
SOAP Request Message Example:
<Soap:envelopeXmlns:soap= "Http://www.w3.org/2003/05/soap-envelope"Soap:encodingstyle= "Http://www.w3.org/2003/05/soap-encoding"> <Soap:body> <Getmobilecodeinfoxmlns= "http://www.example.com"> <Mobilecode>String</Mobilecode> <UserID>String</UserID> </Getmobilecodeinfo> </Soap:body></Soap:envelope>
Examples of SOAP response messages:
<Soap:envelopeXmlns:soap= "Http://www.w3.org/2003/05/soap-envelope"Soap:encodingstyle= "Http://www.w3.org/2003/05/soap-encoding"> <Soap:body> <Getmobilecodeinforesponsexmlns= "http://www.example.com"> <Getmobilecodeinforesult>String</Getmobilecodeinforesult> </Getmobilecodeinforesponse> </Soap:body></Soap:envelope>
Note: The above example indicates the number of mobile phone numbers to obtain information such as attribution. The first example is the request message, and the second example is its response message.
SOAP Fault
Fault
element is used to transmit error and status information in a SOAP message. If an element is included Fault
in a SOAP message, it Body
must appear as a child element and at most one time. Fault
The element itself also contains child elements that describe the details of the error. It contains the following child elements:,,, faultcode
faultstring
faultactor
detail
.
child elements |
Description |
faultcode |
Code for identification of faults |
faultstring |
A description of the fault that can be read by people |
faultactor |
Information about who is causing the failure |
detail |
For Body application-specific error messages involving elements |
This faultcode
is the element that each error message will provide, and its value is typically one of the following error codes:
Error code |
Description |
VersionMismatch |
Invalid SOAP Envelope namespace |
MustUnderstand |
Cannot understand Header child elements that have attributes in mustUnderstand = 1 |
Client |
The message structure is wrong, or contains incorrect information |
Server |
Server error occurred |
Note: The above description of soap Fault is not fully applicable to SOAP version 1.2. Because the SOAP 1.2 version returns an error message, Fault
the child elements and their contents are different. See the following example:
SOAP v1.1 Error Message Example:
<Soap:envelopeXmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/"Soap:encodingstyle= "Http://www.w3.org/2001/12/soap-encoding"> <Soap:body> <Soap:fault> <FaultCode>Soap:client</FaultCode> <faultstring>Input string is not in a correct format.</faultstring> <Detail/> </Soap:fault></Soap:body></Soap:envelope>
SOAP v1.2 Error Message Example:
<Soap:envelopeXmlns:soap= "Http://www.w3.org/2003/05/soap-envelope"Soap:encodingstyle= "Http://www.w3.org/2003/05/soap-encoding"> <Soap:body> <Soap:fault> <Soap:code> <Soap:value>Soap:sender</Soap:value> </Soap:code> <Soap:reason> <Soap:textXml:lang= "en">Input string is not in a correct format.</Soap:text> </Soap:reason> <Soap:detail/> </Soap:fault> </Soap:body></Soap:envelope>
From the above results, the return of the error message content is not much changed, but the XML elements have changed a few, the specific needs of the reader's own understanding.
Turn from 1190000003762279
Introduction to PHP Soap