Because distributed applications are becoming so popular, SOAP, which lets such applications communicate, is becoming popular, too. Plenty of SOAP resources can be found on the Internet; here's a starter list, including W3C's documentation on it:
Here are some SOAP resources for Microsoft's SOAP support:
Let's start digging into this topic now, beginning with the syntax that makes SOAP work. SOAP SyntaxA SOAP message is simply an XML document that adheres to the SOAP syntax rules. There are three parts to a SOAP message:
Here's a simple SOAP message, with an envelope and a body. This SOAP message is requesting the number of pens in stock at the warehouse ( soap-env is the name the W3C uses for the envelope namespace in its documentation): <soap-env:Envelope xmlns:soap-env="http://www.w3.org/2001/12/soap-envelope" soap:soap-enc="http://www.w3.org/2001/12/soap-encoding"> <soap-env:Header> <m:Name xmlns:m="http://www.starpowder.com"> ReallyReallyBigCo </m:Name> </soap-env:Header> <soap-env:Body> <m:NumberInStock xmlns:m="http://www.starpowder.com"> <m:Item>Pens</m:Item> </m:NumberInStock> </soap-env:Body> </soap-env:Envelope> Note that although SOAP messages are XML documents, they must not contain references to DTDs, and they must not contain XML processing instructions. Default namespaces already have been defined for the SOAP envelope and for SOAP encoding and data types. The default namespace for the envelope is http://schemas.xmlsoap.org/soap/envelope/ . The default namespace for the document encoding and data types is http://schemas.xmlsoap.org/soap/encoding/ . So what elements are already defined for SOAP? That's coming up next . SOAP ElementsSOAP messages are XML documents, and the root element is the <Envelope> element. There are three possible child elements: <Header> , <Body> , and <Fault> . All of these elements must use these names, although they can have child elements with different names . Here's what a SOAP envelope might look like: <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" soap-env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> . . . </soap-env:Envelope> The <Header> element is optional and contains application-specific information about the SOAP message. In this example, the locale-specific language is being set to U.S. Englishhere, <m:locale> and <m:language> are user -defined elements: <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" soap-env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <soap-env:Header> <m:locale xmlns:m="http://www.starpowder.com"> <m:language>EN-US</m:language> </m:locale> </soap-env:Header> . . . </soap-env:Envelope> The <Body> element contains the SOAP message itself: <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" soap-env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <soap-env:Header> <m:locale xmlns:m="http://www.starpowder.com"> <m:language>EN-US</m:language> </m:locale> </soap-env:Header> <soap-env:Body> <m:NumberInStock xmlns:m="http://www.starpowder.com"> <m:Item>Pens</m:Item> </m:NumberInStock> </soap-env:Body> </soap-env:Envelope> The <Body> element may also contain a <Fault> element, which you use to hold errors that occurred while working with a message. This element can appear only in response messages, which you get in response to a SOAP message: <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" soap-env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <soap-env:Header> <m:locale xmlns:m="http://www.starpowder.com"> <m:language>EN-US</m:language> </m:locale> </soap-env:Header> <soap-env:Body> <m:NumberInStock xmlns:m="http://www.starpowder.com"> <m:Item>Pens</m:Item> </m:NumberInStock> <soap-env:Fault> <faultcode>soap:Server</faultcode> <faultstring>Server Error</faultstring> </soap-env:Fault> </soap-env:Body> </soap-env:Envelope> There can only be one <Fault> element in a SOAP message, and it can have these subelements:
Here are the possible fault codes:
These SOAP elements can also support various attributes, which are coming up next. SOAP AttributesYou can use these attributes in SOAP elements: actor , encodingStyle , and mustUnderstand . The actor attribute gives the URI for which the header elements are targeted . Here's an example showing how to use the actor attribute: <soap-env:Header> <m:data xmlns:m="http://www.starpowder.com" soap-env:actor="http://www.starpowder.com/accounting" /> <m:language>EN-US</m:language> </m:data> </soap-env:Header> You can use the encodingStyle attribute to specify the data types used in the document. http://schemas.xmlsoap.org/soap/encoding/ is the URI of a schema that the W3C provides for SOAP data types: <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" soap-env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> . . . </soap-env:Envelope> The encodingStyle attribute is optionalyou don't have to use a schema at all to specify the data types that you use in your SOAP message. SOAP schemas can use any of the data types defined for use in XML schemas (see http://www.w3.org/TR/xmlschema-2/) or combinations of them. For all the details on constructing SOAP schemas, see Section 5 of the W3C SOAP Note (http://www.w3.org/TR/SOAP/). You use the mustUnderstand attribute in the <Header> element. It's used to specify whether the target of a message must interpret and process a header element. You set it to a Boolean value, "0" for false and "1" for true: <soap-env:Header> <m:data xmlns:m="http://www.starpowder.com" soap-env:mustUnderstand="1" /> <m:language>EN-US</m:language> </m:data> </soap-env:Header> That gives us an overview of how SOAP works. What about putting SOAP to work? How about using SOAP in codecreating a message, sending it, receiving it, and interpreting it to see how this all works in practice? That's coming up next. |