The SOAP Messaging Framework

SOAP is an XML-based lightweight protocol designed to work with existing Internet and XML open standards. SOAP was originally designed to support the RPC mechanism over HTTP. Later versions removed these restrictions, and SOAP can now be used for both RPC-oriented and message-oriented operations. SOAP is also transport protocol independent.

The first official SOAP specification (SOAP 1) was announced by Microsoft and DevelopMentor in December 1999. IBM and a number of other key industrial players later joined the SOAP specification working group, and in April 2000 the SOAP 1.1 specification was released. In May 2000 the SOAP 1.1 specification was submitted to the W3C as a Note by Microsoft, IBM, UserLand, and DevelopMentor. SOAP is now under the care of the W3C's XML Protocol Working Group (http://www.w3.org/2000/xp/). In this chapter we will look at the more widely supported version 1.1 specification, which can be found at http://www.w3.org/TR/SOAP/. You can find more detailed coverage of the SOAP specifications in Chapter 13.

SOAP rapidly gained widespread industrial acceptance, and today is a core enabler technology for the so-called "Software as Service" revolution in the computer industry. We will have more to say about this revolution, which created what are known as Web Services, later in this chapter.

The SOAP messaging framework consists of three parts: a message structure specification, an encoding standard, and an RPC mechanism. We'll go over each of these parts briefly next.

The Message Structure

A SOAP message is an XML document composed of an outer envelope that can contain a header and a body. This structure is depicted in Figure 7-2.

Figure 7-2 The structure of a SOAP Message.

Listing 7-1 is a skeletal SOAP message with no information in it.

Listing 7-1 soap_skeletal.xml: A skeletal 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> </SOAP-ENV:Header> <SOAP-ENV:Body> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 

The <SOAP-ENV:Envelope> element is the root element of a SOAP message. It is also used to specify options that are global to the whole message, such as the encoding rules of the parameters. <SOAP-ENV:Header> is an optional element that provides a mechanism for participants to add extended information about a call. It's typically used to provide contextual information such as that related to security, transaction, payment, and so forth. The <SOAP-ENV:Body> element is mandatory and is where the actual contents of a message reside. This is where method parameters are encoded and packaged.

A special type of SOAP message, called a fault, is used to indicate when a request has failed for some particular reason, such as an unrecognizable header field, an authentication error, or some errors that occur while processing the message.

Encoding Rules

SOAP has well-defined (some might even say overly designed) rules for encoding complex data structures such as arrays and structures. For example, the following is an array of string encoding in SOAP:

 <SOAP-ENC:Array SOAP-ENC:arrayType="xsd:string[4]"> <SOAP-ENC:string>Item 1</SOAP-ENC:string> <SOAP-ENC:string>Item 2</SOAP-ENC:string> <SOAP-ENC:string>Item 3</SOAP-ENC:string> </SOAP-ENC:Array> 

In addition, SOAP adopts all the types defined in the XML Schema Datatypes specification (http://www.w3c.org/TR/xmlschema-2/). Therefore, for simple types, the XML Schema Datatypes can be used directly in the element schemas.

The SOAP RPC Mechanism

SOAP encoding rules also provide the marshaling and unmarshaling mechanism required to provide RPC-oriented operations. SOAP specifies an RPC mechanism that allows applications to invoke functions on the receiving end of a SOAP message. Function arguments are marshaled using the standard encoding rules as part of the SOAP message body. For instance, the following C# method:

 public int GetValue( int Arg1, int Arg2 ); 

can be marshaled as the following SOAP message:

 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3c.org/2001/XMLSchema/"/> <SOAP-ENV:Body> <GetValue> <Arg1 xsd:type="xsd:int"></Arg1> <Arg2 xsd:type="xsd:int"></Arg2> </GetValue> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 

Note that the method name, GetValue, is encoded as the immediate child element of the <SOAP-ENV:Body> element.



XML Programming
XML Programming Bible
ISBN: 0764538292
EAN: 2147483647
Year: 2002
Pages: 134

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net