Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction.

Similar presentations


Presentation on theme: "1 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction."— Presentation transcript:

1 1 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction

2 2 What is SOAP? SOAP is an XML-based protocol for exchanging information between computers Mainly use for performing remote procedure calls transported via HTTP Different from CORBA, DCOM or Java RMI, SOAP messages are entirely written in XML Hence platform and language independent – E.g. SOAP java client running on Linux can connect to a Microsoft SOAP server running on Windows XP – At the same time, a Perl client running on Solaris can also connect to the same SOAP server EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction

3 3 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction What does SOAP Define? SOAP envelope specification – Specify the rules for encapsulating data being transferred between computers – In case of failure, define how to encode error messages Data encoding rules – Define how the data are encoded – E.g. the rule to encode floating point numbers – Most conventions are based on the W3C XML Schema RPC conventions – Define how a RPC can be proceeded – E.g. how to specify the procedure name, pass parameters and receive response (returned results)

4 4 SOAP vs XML-RPC Similarities – Use XML for messaging – Messages are usually embedded into HTTP header – Use request/response mechanism – Mainly use in remote procedure call – Platform independent – Language independent Differences – SOAP messages are more complicated than XML-RPC – Make use of XML namespaces and XML Schemas – Hence give a standard way for data encoding and RPC – Thus allow automatic method invocation on the Web EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction

5 5 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction SOAP in Action SOAP client SOAP client SOAP server SOAP server XML HTTP SOAP Response SOAP Request Hence SOAP messages can be delivered via the Web

6 6 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction SOAP Communication Styles SOAP supports two different communication styles: – RPC Style Uses the SOAP RPC conventions, hence the communication method and procedure are governed by the conventions Conceptually similar to other RPCs The default of early SOAP implementations – Document Style Also known as message-oriented style Sending non-encoded XML content Require more programming work on server and client sides to interpret the messages More flexible communication and provides the best interoperability

7 7 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction <SOAP-ENV:Envelope xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema”> <ns1: getTemp xmlns:ns1=“urn:xmethods-Temperature” SOAP-ENV:encodingStyle= “http://schemas.xmlsoap.org/soap/encoding/”> 10016 <SOAP-ENV:Envelope xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema”> <ns1: getTemp xmlns:ns1=“urn:xmethods-Temperature” SOAP-ENV:encodingStyle= “http://schemas.xmlsoap.org/soap/encoding/”> 10016 A Sample Request in RPC Style Try to call the remote method getTemp with input parameter, a zipcode: 10016

8 8 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction A Sample Response in RPC Style <SOAP-ENV:Envelope xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema”> <ns1:getTempResponse xmlns:ns1=“urn:xmethods-Temperature” SOAP-ENV:encodingStyle= “http://schemas.xmlsoap.org/soap/encoding/”> 71.0 <SOAP-ENV:Envelope xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema”> <ns1:getTempResponse xmlns:ns1=“urn:xmethods-Temperature” SOAP-ENV:encodingStyle= “http://schemas.xmlsoap.org/soap/encoding/”> 71.0 Return a double 71.0 which represents the temperature

9 9 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction SOAP Messages In most cases, we do not need to directly programming in SOAP Dozens of SOAP implementations now freely exist on the Internet – Apache SOAP (Axis) – Microsoft SOAP ToolKit Allow generating SOAP messages automatically using High Level Language, e.g. Java, C++, Perl Understanding of SOAP message structure enables us to intercept a SOAP transaction and to debug a SOAP application

10 10 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Message Structure SOAP Message Envelope (mandatory) Header (optional) Body (mandatory) Fault (optional)

11 11 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction <SOAP-ENV:Envelope : : : : : : <SOAP-ENV:Envelope : : : : : : Header: Optional Envelope: Mandatory Body: Mandatory Fault: Optional Example

12 12 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction SOAP message – Envelope Every SOAP message has a root Envelope element Does not define the SOAP version Rather, use namespaces to differentiate versions For SOAP 1.2, the namespace URI is – http://www.w3.org/2001/09/soap-envelope <SOAP-ENV:Envelope xmlns:SOAP-ENV= “http://schemas.xmlsoap.org/soap/envelope/” : <SOAP-ENV:Envelope xmlns:SOAP-ENV= “http://schemas.xmlsoap.org/soap/envelope/” : Namespace for SOAP 1.1

13 13 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction XML Namespaces XML document can define its own markup language or vocabularies XML uses namespace to uniquely identify XML vocabularies <SOAP-ENV:Envelope xmlns:SOAP-ENV= “http://schemas.xmlsoap.org/soap/envelope/” : <SOAP-ENV:Envelope xmlns:SOAP-ENV= “http://schemas.xmlsoap.org/soap/envelope/” : Define the namespace of SOAP-ENV is Define also element Envelope is part of namespace SOAP-ENV Attribute for defining namespace

14 14 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction We do not need to really go to http://schemas.xmlsoap.org/soap/envelope/” to do anything Since this URL is unique, the word SOAP-ENV is also unique in this document If there is another XML document that has the same word SOAP-ENV but referring to different URL, it means that SOAP-ENV is different from this SOAP-ENV In contrary, if they refer to the same URL, it means that the two SOAP-ENV are referring to the same thing

15 15 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction <SOAP-ENV:Envelope xmlns:SOAP-ENV= “http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema”> : <SOAP-ENV:Envelope xmlns:SOAP-ENV= “http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema”> : Define the namespaces for data encoding Need to specify this to server to declare the data in the document are encoded based on a particular convention Again, we do not need to really go to these Web sites to do anything. Just to imply uniqueness and for verification purpose

16 16 Header EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction <SOAP-ENV:Envelope : : : : : : <SOAP-ENV:Envelope : : : : : : Optional. For specifying additional application-level requirements For example: (1) specify a digital signature; (2) specify an account number

17 17 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Body <SOAP-ENV:Envelope : : : : : : <SOAP-ENV:Envelope : : : : : : Mandatory to all SOAP messages Carry the actual content such as the RPC requests or responses

18 18 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Fault <SOAP-ENV:Envelope : : : : : : <SOAP-ENV:Envelope : : : : : : In case of error, the body element should contain a fault sub-element Indicate the error code and the possible cause of error

19 19 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Element nameDescription faultCodeA text code to indicate the class of error faultStringA human-readable explanation of error faultActorA text string indicating who caused the fault. Particularly useful when the SOAP message travels a few nodes detailCarry application-specific error message May contain the following elements

20 20 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction SOAP-ENV:Client Failed to locate method (ValidateCreditCard) in class (examplesCreditCard) at /usr/local/ActivePerl-5.6/lib/ site_perl/5.6.0/SOAP/Lite.pm line 1555. SOAP-ENV:Client Failed to locate method (ValidateCreditCard) in class (examplesCreditCard) at /usr/local/ActivePerl-5.6/lib/ site_perl/5.6.0/SOAP/Lite.pm line 1555. For example

21 21 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Samples of fault codes NameDescription SOAP-ENV:VersionMismatchEnvelope element includes an invalid namespace SOAP-ENV:ClientIndicate the client request contained an error SOAP-ENV:ServerIndicate the server is unable to process the client request

22 22 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction SOAP Data Encoding A data is just a sequence of 1 and 0 To allow different computers understand the meaning of a data (string, integer, float …), a standard data type encoding method is required The original XML 1.0 specification does not include rules for encoding data type Later W3C released the XML Schema and provided a standard framework for encoding data type SOAP specification adopted the XML Schema, with exception such as arrays and structs

23 23 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Scalar Types A scalar type data contains exactly one value – e.g. string, Boolean, float, double. int, date, time, etc… SOAP adopts all the built-in simple types specified by XML Schema For details, see http://www.w3.org/TR/2000/WD-xmlschema-0- 20000407/

24 24 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction <ns1:getPriceResponse xmlns:ns1="urn:examples:priceservice“ SOAP-ENV:encodingStyle= "http://www.w3.org/2001/09/soap-encoding"> 54.99 <ns1:getPriceResponse xmlns:ns1="urn:examples:priceservice“ SOAP-ENV:encodingStyle= "http://www.w3.org/2001/09/soap-encoding"> 54.99 For example xsi:type is set to xsd:double, means a double number is to be returned Follow the SOAP 1.2 encoding method. For SOAP 1.1, use schemas.xmlsoap.org/soap/encoding/

25 25 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Compound Types Compound type data contains multiple values Can be further divided into arrays and structs Arrays contain multiple values of the same type – Some implementations support multidimensional array Structs contain multiple values, but each element is specified by a name

26 26 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Arrays Need to specify both the element type and array size <return xmlns:ns2= “http://www.w3.org/2001/09/soap-encoding” xsi:type=“ns2:Array” ns2:arrayType=“xsd:double[2]”> 54.99 19.99 <return xmlns:ns2= “http://www.w3.org/2001/09/soap-encoding” xsi:type=“ns2:Array” ns2:arrayType=“xsd:double[2]”> 54.99 19.99 Specify the type is array and there are two double numbers in the array

27 27 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Structs Struct contains multiple values, but each element is specified with a unique accessor element <return xmlns:ns2="urn:examples" xsi:type="ns2:product"> Red Hat Linux 54.99 Red Hat Linux Operating System A358185 <return xmlns:ns2="urn:examples" xsi:type="ns2:product"> Red Hat Linux 54.99 Red Hat Linux Operating System A358185 Accessor names

28 28 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Literal Encoding It is possible to ignore all the SOAP specification and embed a generic XML document directly into a SOAP message Doing so is referred to as literal encoding Different implementation may have different ways to encode literal XML document For Apache SOAP, need to specify the namespace http://xml.apache.org/xml-soap/literalxml

29 29 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction SOAP-ENV:encodingStyle= "http://xml.apache.org/xml-soap/literalxml"> Red Hat Linux Red Hat Linux Operating System 54.99 SOAP-ENV:encodingStyle= "http://xml.apache.org/xml-soap/literalxml"> Red Hat Linux Red Hat Linux Operating System 54.99 Doing the same as the struct example but without the SOAP rules. Solely in generic XML format Specify the encoding style

30 30 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction The two communication styles (RPC, document) and two encodings (encoded, literal) methods can be freely intermixed – RPC / encoded Following SOAP RPC convention for messaging and also following SOAP data encoding method Most straightforward to implement but also most restrictive Can introduce interoperability problem Most popularly used in early version of SOAP implementation (WebSphere 4 and 5.0) – RPC / literal Following SOAP RPC convention for messaging but sending literal XML data Less restrictive

31 31 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction – Document / literal Sending non-encoded XML message with literal XML data Need more programming work for the server and client to interpret the data Provide the best interoperability between Java and non- Java implementations Default for recently implementation of SOAP (WebSphere 5.1 and Microsoft Toolkit 3.0) – Document / encoded Not used in practice

32 32 SOAP Interoperability EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Although SOAP was developed to solve the interoperability problem when doing RPC, it also has interoperability problem For example, there is known problem between Apache SOAP, SOAP::Lite for Perl and the Microsoft SOAP Toolkit Apache SOAP requires all parameters to be typed via the xsi:type attribute, while others don’t Microsoft SOAP Toolkit supports multidimensional array while others don’t Much effort has been made, but still some way to go to totally solve the problem

33 33 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Web Services Interoperability (WS-I) WS-I is an organization chartered to promote Web service interoperability across platforms, OS and programming languages (see http://www.ws-i.org/) Establish WS-I Basic Profile which outlines the requirements to which WSDL and Web service protocol (SOAP/HTTP) traffic must comply Provide WS-I validation tools currently support WS-I Basic Profile 1.0 One of the important suggestions made is the banning of RPC / encoded style However, the use of RPC / encoded style provides much convenience in exposing preexisting classes and methods Much work is being performed to make sure the RPC style works between most SOAP implementations


Download ppt "1 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction."

Similar presentations


Ads by Google