SCDJWS Study Guide: SOAP
The Envelope element is the root element for all SOAP messages, identifying the XML as a SOAP message. The Envelope element must be present in a SOAP message. The Envelope element, as its name would suggest, serves as a container for the other elements of the SOAP message. As it is the top element, the Envelope is the message. An optional Header element and a mandatory Body element are child elements of the Envelope element. Both Header and Body elements are in the http://schemas.xmlsoap.org/soap/envelope/ namespace.
The Envelope element MAY contain namespace declarations as well as additional attributes. If present, such additional attributes MUST be namespace-qualified. Similarly, the element MAY contain additional sub elements. If present these elements MUST be namespace-qualified and MUST follow the SOAP Body element.
<xs:element ref="tns:Header" minOccurs="0" />
<xs:element ref="tns:Body" minOccurs="1" />
<xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
<xs:anyAttribute namespace="##other" processContents="lax" />
A typical SOAP message can also include the encoding style, which assists the recipient in interpreting the message.
<?xml version="1.0" encoding="UTF-8"?>
<!-- extensions of Header blocks go here -->
<!-- message payload goes here -->
You can see that an encoding is specified within the envelope, allowing an application to determine (using the value of the encodingStyle attribute) whether it can read the incoming message situated within the Body element.
attribute is used to indicate the use of a particular scheme in the
encoding of data into XML. However, this introduces complexity, as this
function can also be served by the use of XML Namespace. As a result,
the WS-I Basic Profile 1.0 prefers the use of literal, non-encoded XML.
Basic Profile 1.0]
||A MESSAGE MUST NOT contain soap:encodingStyle attributes on any of the elements whose namespace name is "http://schemas.xmlsoap.org/soap/envelope/".|
||A MESSAGE MUST NOT contain soap:encodingStyle attributes on any element that is a child of soap:Body.|
||A MESSAGE described in an rpc-literal binding MUST NOT contain soap:encodingStyle attribute on any elements are grandchildren of soap:Body.|
Be sure to get the SOAP Envelope namespace correct, otherwise you won't be able to interoperate with them. SOAP does not define a traditional versioning model based on major and minor version numbers. A SOAP message MUST have an Envelope element associated with the http://schemas.xmlsoap.org/soap/envelope/ namespace. If a message is received by a SOAP application in which the SOAP Envelope element is associated with a different namespace, the application >MUST treat this as a version error and discard the message. If the message is received through a request/response protocol such as HTTP, the application MUST respond with a SOAP VersionMismatch faultcode message using the SOAP "http://schemas.xmlsoap.org/soap/envelope/" namespace.
SOAP 1.1 states that a message with an Envelope element with a namespace name other than http://schemas.xmlsoap/soap/envelope/ should be discarded. The WS-I Basic Profile 1.0 requires that a Fault be generated instead, to assure unambiguous operation. [WS-I Basic Profile 1.0]
||A RECEIVER MUST generate a fault if they encounter a message whose document element has a local name of "Envelope" but a namespace name that is not "http://schemas.xmlsoap/soap/envelope/"|