using xml for distributed computing xml-rpc and soap mark lewis 10-19-2000

33
Using XML for Using XML for Distributed Computing Distributed Computing XML-RPC and SOAP XML-RPC and SOAP Mark Lewis Mark Lewis 10-19-2000 10-19-2000

Post on 22-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Using XML for Distributed Using XML for Distributed ComputingComputing

XML-RPC and SOAPXML-RPC and SOAP

Mark LewisMark Lewis

10-19-200010-19-2000

OverviewOverview

MotivationMotivation XML-RPCXML-RPC SOAPSOAP Comparison and analysisComparison and analysis ConclusionsConclusions

MotivationMotivation

These protocols have been developed These protocols have been developed to provide a platform and language to provide a platform and language independent method of passing independent method of passing information between machines.information between machines.

They are not at this point a They are not at this point a replacement for Java-RMI or CORBA, replacement for Java-RMI or CORBA, but they do provide simple but they do provide simple standardized mechanisms for moving standardized mechanisms for moving structured information.structured information.

XML-RPCXML-RPC (Remote Procedure (Remote Procedure Calls)Calls)

This specification was created by This specification was created by UserLand Software Inc. to provide a UserLand Software Inc. to provide a simple way for processes on distant simple way for processes on distant machines to exchange information.machines to exchange information.

It specifies a common format for It specifies a common format for packaging information as well as packaging information as well as submitting requests and returning submitting requests and returning the replies.the replies.

Request ExampleRequest ExamplePOST /RPC2 HTTP/1.0User-Agent: Frontier/5.1.2 (WinNT)Host: betty.userland.comContent-Type: text/xmlContent-length: 181

<?xml version="1.0"?><methodCall> <methodName>examples.getStateName</methodName> <params> <param> <value><i4>41</i4></value> </param> </params></methodCall>

<methodCall><methodCall>

The XML data for an XML-RPC call must The XML data for an XML-RPC call must be contained in a single <methodCall> be contained in a single <methodCall> structure.structure.

It must contain a <methodName> sub-It must contain a <methodName> sub-item that specifies the method to be item that specifies the method to be called. It is up to the server to decide called. It is up to the server to decide what to do with it.what to do with it.

If parameters are expected a If parameters are expected a <params> sub-item must be given.<params> sub-item must be given.

Data TagsData Tags

The <params> element can have The <params> element can have any number of <param> any number of <param> subelements each of which must subelements each of which must contain a value.contain a value.

Scalar value tagsScalar value tags– <i4> or <int>, <boolean>, <string>, <i4> or <int>, <boolean>, <string>,

<double>, <dateTime.iso8601>, <double>, <dateTime.iso8601>, <base64><base64>

<struct><struct> Structs contain members and can Structs contain members and can

be recursive.be recursive.<struct> <member> <name>lowerBound</name> <value><i4>18</i4></value> </member> <member> <name>upperBound</name> <value><i4>139</i4></value> </member></struct>

<array><array>

These contain a single <data> These contain a single <data> element and can be recursive.element and can be recursive.

<array> <data> <value><i4>12</i4></value> <value><string>Egypt</string></value> <value><boolean>0</boolean></value> <value><i4>-31</i4></value> </data></array>

Response ExampleResponse ExampleHTTP/1.1 200 OKConnection: closeContent-Length: 158Content-Type: text/xmlDate: Fri, 17 Jul 1998 19:55:08 GMTServer: UserLand Frontier/5.1.2-WinNT

<?xml version="1.0"?><methodResponse> <params> <param> <value><string>South Dakota</string></value> </param> </params></methodResponse>

Response SyntaxResponse Syntax

The <methodResponse> tag The <methodResponse> tag contains one <params> which contains one <params> which contains one <param> which contains one <param> which contains a single <value>.contains a single <value>.

It can also contain a fault It can also contain a fault structure.structure.

FaultsFaults

XML-RPC defines one structure XML-RPC defines one structure which is the fault return structure.which is the fault return structure.

A <fault> contains one value A <fault> contains one value which is a <struct> which has a which is a <struct> which has a faultCode that is an int and a faultCode that is an int and a faultString which is a string. faultString which is a string.

Notes on XML-RPCNotes on XML-RPC

XML-RPC is simple in the extreme. XML-RPC is simple in the extreme. The specification takes literally The specification takes literally four pages with the examples.four pages with the examples.

This might be a little too simple. This might be a little too simple. The simplicity definitely restricts The simplicity definitely restricts the applications that this can be the applications that this can be used for.used for.

SOAPSOAP (Simple Object Access (Simple Object Access Protocol)Protocol)

SOAP is actually intended to just be a SOAP is actually intended to just be a protocol for exchange of information protocol for exchange of information which gives it a somewhat more which gives it a somewhat more broad usage than simply RPC.broad usage than simply RPC.

It certainly addresses the argument It certainly addresses the argument that XML-RPC was too simple. I’m that XML-RPC was too simple. I’m just not convinced that it is gaining just not convinced that it is gaining much from the complication.much from the complication.

SOAP Request ExampleSOAP Request Example

<SOAP-ENV:Envelope xmlns:SOAP-ENV= "http://schemas.xmlsoap.org/soap/envelope/” SOAP-ENV:encodingStyle= "http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="Some-URI"> <symbol>DIS</symbol> </m:GetLastTradePrice> </SOAP-ENV:Body></SOAP-ENV:Envelope>

SOAP Response ExampleSOAP Response Example

<SOAP-ENV:Envelope xmlns:SOAP-ENV= "http://schemas.xmlsoap.org/soap/envelope/” SOAP-ENV:encodingStyle= "http://schemas.xmlsoap.org/soap/encoding/"/> <SOAP-ENV:Body> <m:GetLastTradePriceResponse xmlns:m="Some-URI"> <Price>34.5</Price> </m:GetLastTradePriceResponse> </SOAP-ENV:Body></SOAP-ENV:Envelope>

General StructureGeneral Structure

Envelope - This is the top level of the Envelope - This is the top level of the SOAP message and must be present.SOAP message and must be present.

Header - This is optional but if it occurs Header - This is optional but if it occurs it must be the first child of the it must be the first child of the envelope.envelope.

Body - This must be present either as Body - This must be present either as the first child or following the header. It the first child or following the header. It is where the data of the message is is where the data of the message is stored.stored.

EnvelopeEnvelope

It must be associated with the It must be associated with the namespace namespace “http://schemas.xmlsoap.org/soap/“http://schemas.xmlsoap.org/soap/envelope”.envelope”.

It can have an encdongStyle It can have an encdongStyle attribute that contains a URI attribute that contains a URI describing how the data should be describing how the data should be serialized.serialized.

HeaderHeader

The actor attribute defines “who” The actor attribute defines “who” needs to deal with a header element.needs to deal with a header element.– When an actor is specified the proper When an actor is specified the proper

layer deals with that header element and layer deals with that header element and doesn’t pass it on.doesn’t pass it on.

– Default is the final recipient of the Default is the final recipient of the message.message.

The mustUnderstand attribute is a The mustUnderstand attribute is a boolean.boolean.

BodyBody

The data carried in the body is like The data carried in the body is like data in the Header that is intended data in the Header that is intended for the final destination with for the final destination with mustUnderstand=“1”.mustUnderstand=“1”.

Body entries are identified by the Body entries are identified by the namespace URI and the local name.namespace URI and the local name.

The immediate children may be The immediate children may be namespace qualified.namespace qualified.

FaultsFaults

As with XML-RPC, SOAP defines only one As with XML-RPC, SOAP defines only one body entry which is a fault.body entry which is a fault.

SOAP Faults have four subelements: SOAP Faults have four subelements: faultcode, faultstring, faultactor, and faultcode, faultstring, faultactor, and detail.detail.

The SOAP faultcodes are also somewhat The SOAP faultcodes are also somewhat more robust using strings that use the more robust using strings that use the “dot” notation to refine the nature of “dot” notation to refine the nature of the error like “Client.Authentication”.the error like “Client.Authentication”.

TypesTypes

The typing in SOAP is largely based on The typing in SOAP is largely based on the XML Schema Parts1 and 2 the XML Schema Parts1 and 2 (Structures and Datatypes)(Structures and Datatypes)

The typing goes a bit beyond this to The typing goes a bit beyond this to model the types found in programming model the types found in programming languages.languages.

The payload of a SOAP message is The payload of a SOAP message is data only. It may not contain data only. It may not contain processing instructions.processing instructions.

EnumerationsEnumerations

One way in which SOAP extends One way in which SOAP extends types is by adding enumerated types is by adding enumerated values.values.

<element name="EyeColor" type="tns:EyeColor"/><simpleType name="EyeColor" base="xsd:string"> <enumeration value="Green"/> <enumeration value="Blue"/> <enumeration value="Brown"/></simpleType>

Single-Reference vs. Multi-Single-Reference vs. Multi-ReferenceReference

SOAP allows values to be referenced SOAP allows values to be referenced multiple times using ids or hrefs.multiple times using ids or hrefs.

When a piece of data is single When a piece of data is single referenced the specification states that referenced the specification states that it should be defined in a way which it should be defined in a way which implies this.implies this.

SOAP allows optimization of some multi-SOAP allows optimization of some multi-reference types and when possible reference types and when possible treating multi-reference data as single-treating multi-reference data as single-reference data.reference data.

StructsStructs

SOAP allows for complex types where SOAP allows for complex types where the elements have accessor names.the elements have accessor names.

If the accessor names are unique it is If the accessor names are unique it is called a structure.called a structure.

The definition of a struct is The definition of a struct is accomplished by the XML Schema accomplished by the XML Schema complexType. As such they can be complexType. As such they can be recursive.recursive.

ArraysArrays

A complex type where ordinal position A complex type where ordinal position is the only way to distinguish elements is the only way to distinguish elements is an array.is an array.

All arrays have the type SOAP-All arrays have the type SOAP-ENC:Array or some subtype of it.ENC:Array or some subtype of it.

Each element can have a different Each element can have a different type by defining an xsi:type and arrays type by defining an xsi:type and arrays can be recursive or multidimensional.can be recursive or multidimensional.

Sparse and Partially Sparse and Partially Transmitted ArraysTransmitted Arrays

By supplying a SOAP-ENC:offset By supplying a SOAP-ENC:offset arrays can be only partially specified arrays can be only partially specified (ex. an array with 5 elements but (ex. an array with 5 elements but only [2] and [3] are specified).only [2] and [3] are specified).

Sparse matrices can be made using Sparse matrices can be made using SOAP-ENC:position.SOAP-ENC:position.

Doesn’t say what the unspecified Doesn’t say what the unspecified elements take as a value.elements take as a value.

PolymorphismPolymorphism

The SOAP spec acknowledges that The SOAP spec acknowledges that many programming languages many programming languages include the concept of include the concept of polymorphism but doesn’t do polymorphism but doesn’t do much beyond that.much beyond that.

It requires that a type be specified It requires that a type be specified for parametric values instead of for parametric values instead of just allowing the default.just allowing the default.

RPC with SOAPRPC with SOAP

The SOAP specification is a bit The SOAP specification is a bit more strict about the manner of more strict about the manner of passing information to a method in passing information to a method in requiring the passed data must requiring the passed data must match the method signature.match the method signature.

However, it does not require a However, it does not require a different syntax for requests and different syntax for requests and responses.responses.

Notes on SOAPNotes on SOAP

The SOAP specification is in general The SOAP specification is in general much more specific and detailed much more specific and detailed than the XML-RPC specification but than the XML-RPC specification but they needed 29 pages to do it.they needed 29 pages to do it.

However, it doesn’t even attempt However, it doesn’t even attempt to address what I saw as many of to address what I saw as many of the limitations of the XML-RPC the limitations of the XML-RPC implementation.implementation.

AnalysisAnalysis

Order of elements is structures in not Order of elements is structures in not considered in XML-RPC.considered in XML-RPC.

RestrictionsRestrictions– Neither allows distributed garbage Neither allows distributed garbage

collection, remote references, or collection, remote references, or activation.activation.

Since SOAP can’t include functionality Since SOAP can’t include functionality it seems it should be SSAP instead.it seems it should be SSAP instead.

ConclusionsConclusions These two specification definitely have These two specification definitely have

their applications though I’m not their applications though I’m not convinced that either is truly an convinced that either is truly an acceptable way of doing RPC.acceptable way of doing RPC.

They work well for fairly simple data They work well for fairly simple data transmission and for that reason I prefer transmission and for that reason I prefer the simpler of the two. It’s not clear to the simpler of the two. It’s not clear to me how many of the restrictions in me how many of the restrictions in SOAP can be enforced or used to help SOAP can be enforced or used to help programmers.programmers.

SpecsSpecs

XML-RPC spec is atXML-RPC spec is at– http://www.xml-rcp.com/spechttp://www.xml-rcp.com/spec

SOAP spec is atSOAP spec is at– http://msdn.microsoft.com/http://msdn.microsoft.com/

workshop/xml/general/soapspec.aspworkshop/xml/general/soapspec.asp