I l @ ve RuBoard |
Similar in concept, yet far broader in scope and implication , is the Simple Object Access Protocol (SOAP), an emerging W3C standard for decentralized information exchange between peers in a networked environment. Designed specifically for information transfer between distributed applications and objects built on different platforms, and layered (like XML-RPC) on XML and HTTP, SOAP has the support of industry heavyweights such as Microsoft, IBM, HP, Ariba, Lotus, and SAP, and is expected to shortly reach W3C Recommendation status. SOAP is, fundamentally, a framework for stateless data exchange between systems. It is a specification for the creation of structured, typed data packets designed for easy transmission across a network. As of this writing, the SOAP specification addresses merely the structure of SOAP packets and the SOAP processing model, leaving items such as the mechanics of packet transmission and routing, packet integrity, and security to be handled at the application layer. It is not necessary that the data encoded using SOAP be an RPC request or response. SOAP can be used to transfer data of any kind ”RPC is just one example of its applications. A SOAP packet is a well- formed XML document consisting of the following three primary parts :
Take a look at Listing 6.4, which demonstrates the SOAP equivalent of the RPC request you saw in Listing 6.1. Listing 6.4 A SOAP RequestPOST /SOAPServer HTTP/1.0 User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 95) Host: some.quote.server Content-Type: text/xml Content-Length: 360 <?xml version="1.0" ?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http:// www.w3.org/1999/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/ "> <soap:Body> <getRandomQuote> <xsd:string>Shakespeare</xsd:string> </getRandomQuote> </soap:Body> </soap:Envelope> As you can see, an RPC request is encoded within the body of the SOAP packet as a series of nested elements, with the name of the first element in the body corresponding to the name of the remote procedure. Arguments to the remote procedure are specified as elements within this outermost element. Unlike XML-RPC, it is not necessary that a SOAP response return an HTTP status code of 200 OK ; rather, the SOAP specification suggests the use of standard HTTP error codes to identify whether the request was successfully received and processed . The results of a successful RPC invocation would resemble Listing 6.5 (note the Response suffix added to the element containing the return value). Listing 6.5 A SOAP Response to a Successful SOAP RequestHTTP/1.0 200 OK Server: QuoteServer/SOAP Connection: close Content-Type: text/xml Content-Length: 435 <?xml version="1.0" ?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http:// www.w3.org/1999/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <soap:Body> <getRandomQuoteResponse> <xsd:string>Good night, sweet prince, and flights of angels sing thee to thy rest.</xsd:string> </getRandomQuoteResponse> </soap:Body> </soap:Envelope> If an error occurs while processing the remote procedure, a fault is generated and returned to the client, with the fault information encoded within the body of the SOAP packet. Listing 6.6 demonstrates this with an example. Listing 6.6 A SOAP Response to an Unsuccessful SOAP RequestHTTP/1.0 500 Internal Server Error Server: QuoteServer/SOAP Connection: close Content-Type: text/xml Content-Length: 545 <?xml version="1.0" ?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http:// www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" soap: encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <soap:Body> <soap:Fault> <faultstring xsi:type="xsd:string">Server error. Method not found. getRandomQuote</faultstring> <faultcode xsi:type="xsd:string">soap:Client</faultcode> </soap:Fault> </soap:Body> </soap:Envelope> For more information and examples, you should refer to the W3C's SOAP primer at http://www.w3.org/TR/soap12-part0/, which contains the official SOAP specification. (See the book's companion web site at http://www.xmlphp.com or http://www.newriders.com for more specific links.) You might also want to visit http://www.soapware.org/, a directory of SOAP implementations for numerous different languages and platforms.
|
I l @ ve RuBoard |