WebReference.com - Part 1 of Chapter 3: Professional XML Web Services, from Wrox Press Ltd (3/7) | WebReference

WebReference.com - Part 1 of Chapter 3: Professional XML Web Services, from Wrox Press Ltd (3/7)

To page 1To page 2current pageTo page 4To page 5To page 6To page 7
[previous] [next]

Professional XML Web Services

SOAP Messages

Now that we have covered SOAP at a high level, let's examine the most important detail of SOAP: the structure of a message. First and foremost, SOAP uses XML syntax for messages. The structure of a SOAP message is shown overleaf:

SOAP Message Syntax Diagram

The diagram shows how a SOAP message can be broken down into components, and we will cover each of these in detail. A SOAP message contains a payload, the application-specific information. Here is an example of a SOAP message as an actual XML document:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
               soap:encodingStyle="http://schemas.xmlsoap.org/soap/
                                   encoding/">
   <soap:Header>
      <h:from xmlns:h="http://www.wrox.com/Header">SoapGuy@wrox.com</h:from>
   </soap:Header>
   <soap:Body>
      <w:GetSecretIdentity xmlns:w="http://www.wrox.com/heroes/">
         <w:codename>XSLT-Man</w:codename>
      </w:GetSecretIdentity>
   </soap:Body>
</soap:Envelope>

Before we go into the contents of the SOAP message, let's take a quick glance at the XML of the message. As can be seen, SOAP messages rely heavily on XML Namespaces. All of the elements in this document are prefixed with a namespace, and there is a good reason why the SOAP specification uses namespaces so extensively. In order for a SOAP message to carry any arbitrary XML payload, all the elements of the message must be scoped in some fashion to avoid conflicts in the names of elements.

The Namespaces in XML Recommendation can be found at http://www.w3.org/TR/REC-xml-names/.

The namespace prefix soap is used on most of the elements in the above message. In this example, the prefix is associated with the namespace URI http://schemas.xmlsoap.org/soap/envelope/, and it identifies the elements that are part of a standard SOAP message. Like all namespace prefixes, the choice of soap is irrelevant. The namespace prefix could have been something else entirely, as in this message:

<blah:Envelope xmlns:blah ="http://schemas.xmlsoap.org/soap/envelope/" 
               blah:encodingStyle="http://schemas.xmlsoap.org/
                                   soap/encoding/">
   <blah:Header>
      <h:from xmlns:h="http://www.wrox.com/Header">SoapGuy@wrox.com</h:from>
   </blah:Header>
   <blah:Body>
      <w:GetSecretIdentity xmlns:w="http://www.wrox.com/heroes/">
         <w:codename>XSLT-Man</w:codename>
      </w:GetSecretIdentity>
   </blah:Body>
</blah:Envelope>

The namespace prefix could also be eliminated completely if the namespace is the default namespace for the document. The default namespace is assigned using just the xmlns attribute, as shown here:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" 
          encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <Header>
      <h:from xmlns:h="http://www.wrox.com/Header">SoapGuy@wrox.com</h:from>
   </Header>
   <Body>
      <w:GetSecretIdentity xmlns:w="http://www.wrox.com/heroes/">
         <w:codename>XSLT-Man</w:codename>
      </w:GetSecretIdentity>
   </Body>
</Envelope>

All three of these messages are acceptable and equivalent. For the sake of readability, it is better to use the soap namespace prefix for elements.

All of the elements in the message that are associated with the soap namespace are standard elements of a SOAP message, as are the attributes. Any other elements are either related to message extensions or the message payload. There are three standard SOAP elements that appear in this sample message: the Envelope, the Body, and the Header. There is also one other standard element that does not appear in this example message, the Fault element, which we will discuss later in this chapter.


To page 1To page 2current pageTo page 4To page 5To page 6To page 7
[previous] [next]

Created: November 12, 2001
Revised: November 12, 2001


URL: http://webreference.com/authoring/languages/xml/webservices/chap3/1/3.html