SOAP Basics
This section reviews the basics of SOAP. After reading this section, you will be able to find your way through common SOAP interactions. The next section zooms in on some of these topics and provides the missing details.
At the time of writing, SOAP is not an official W3C standard. Two somewhat incompatible versions of SOAP coexist:
SOAP 1.1 is defined in two W3C notes available from http://www.w3.org/TR/SOAP and http://www.w3.org/TR/SOAP-attachments.
SOAP 1.2 is available as a W3C working draft from http://www.w3.org/TR/soap12-part1 and http://www.w3.org/TR/soap12-part2. At the time of writing this version is still under development.
Note that SOAP 1.1 is not officially endorsed by W3C. It is available only on the W3C site as notes. Notes (as opposed to recommendations such as XML) are working documents prepared by W3C members and published for information only. Notes are intended to elicit comments.
The most visible difference between SOAP 1.1 and SOAP 1.2 is the use of XML namespaces. SOAP 1.1 builds all its namespaces from the http://schemas.xmlsoap.org/soap root, whereas SOAP 1.2 uses http://www.w3.org/2001/09/soap.
CAUTION
Because they use different namespaces, the two versions of SOAP are not directly compatible. Otherwise they are mostly similar.
The remainder of this article concentrates on the similarities and highlights the differences only where relevant.
Other differences are mostly editorial. SOAP 1.2 is better written: it contains fewer ambiguities and is generally easier to read.
TIP
If you have problems when reading the SOAP 1.1 specification, look up the corresponding section in the SOAP 1.2 spec.
SOAP Architecture
The most striking difference between SOAP and XML-RPC is that SOAP leaves so many options open. XML-RPC provided a closed solution to one problem: sending RPC requests over HTTP.
SOAP, on the other hand, is more like a toolbox. It defines a messaging framework (the envelope), encoding rules and a binding to the HTTP protocol. RPC needs all three but you can build SOAP requests with the envelope, the HTTP binding, and then use other encoding rules. Or you can use the envelope, the encoding rules, and another communication protocol.
Figure 1 illustrates this. At the bottom of the stack are HTTP and SMTP, two communication protocols developed independently from SOAP. They control sending and receiving files.
Figure 1 Logical view of SOAP.
SOAP attaches to those protocols through bindings (note that, at the time of writing, the SMTP binding is not official). On top of the binding comes the message framework that lays down the rules that organize SOAP messages. What goes in the messages? That's the role of the encoding rules. Finally the RPC uses the encoding rules to create a message, which is stored in an envelope (the message framework), and sent over HTTP.
Notice the ebXML Transport, Routing, and Packaging in Figure 1. The ebXML initiative develops e-commerce solutions with XML (see http://www.ebxml.org for more information). It uses the messaging framework and the SOAP bindings, but it has its own encoding rules. The ebXML initiative helps illustrate that SOAP is a toolbox from which you can pick and choose those elements that make sense for you.
Unfortunately, what is gained in flexibility is lost in simplicity. SOAP can be very confusing when you try to find your way through the maze of options. Also the options may result in incompatibilities. For example, although ebXML uses SOAP, it is not directly compatible with SOAP RPC because it does not use the same encoding rules.
TIP
If you ever get lost in the SOAP options, remember that, taken individually, each option is simple. Although the number of options may be confusing, they are not difficult to understand. If you understand how two options relate one to another, you should do fine.
SOAP Blocks and Elements
The messaging framework defines the basic XML elements you need to construct SOAP requests. SOAP defines the request in terms of SOAP blocks where a block is a single logical computational unit. The block is represented as an XML element identified by a qualified name, that is, a combination of local name and namespace.
XML Namespaces
A SOAP message contains elements defined by different sources: some are defined by the SOAP recommendation itself, others come from the XML schema recommendation and, finally, it is likely to also contain elements defined by the programmer.
The fact that different sources collaborate to create a document may cause conflicts and, in particular, naming conflicts.
XML namespaces is a standard mechanism (defined by the W3C) to avoid name conflicts. For example, if the programmer has defined a Body element, the namespace helps distinguish this Body element from the SOAP body. In that respect, namespaces are similar to Java packages.
To guarantee uniqueness, XML namespaces are URIs that are bound to prefixes through an xmlns attribute.
For example,
<env:Envelope xmlns:env=http://schemas.xmlsoap.org/soap/envelope/">
binds the http://schemas.xmlsoap.org/soap/envelope/ namespace with the env prefix. Only the prefix appears in the remainder of the document. For example:
<env:Body>
The name after the prefix is said to be the local name. Again note the similarity with Java packages that also use domain names to guarantee the uniqueness of names.
Unfortunately, because SOAP uses HTTP, SOAP nodes are also identified by URIs, and this creates some confusion. To avoid confusion, remember that URIs to xmlsoap.org and w3.org are likely to be namespaces.