1 / 33

EIE424 Distributed Systems and Networking Programming –Part II

EIE424 Distributed Systems and Networking Programming –Part II. 3.1 SOAP – Introduction. 3.1 SOAP – Introduction. EIE424 Distributed Systems and Networking Programming –Part II. 3.1 SOAP – Introduction. What is SOAP?.

maxima
Download Presentation

EIE424 Distributed Systems and Networking Programming –Part II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction 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

  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. EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction 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

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

  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. EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction A Sample Request in RPC Style <?xml version=‘1.0’ encoding=‘UTF-8’?> <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:Body> <ns1:getTemp xmlns:ns1=“urn:xmethods-Temperature” SOAP-ENV:encodingStyle= “http://schemas.xmlsoap.org/soap/encoding/”> <zipcode xsi:type=“xsd:string”>10016</zipcode> </ns1:getTemp> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Try to call the remote method getTemp with input parameter, a zipcode: 10016

  8. EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction A Sample Response in RPC Style <?xml version=‘1.0’ encoding=‘UTF-8’?> <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:Body> <ns1:getTempResponse xmlns:ns1=“urn:xmethods-Temperature” SOAP-ENV:encodingStyle= “http://schemas.xmlsoap.org/soap/encoding/”><return xsi:type=“xsd:float”>71.0</return> </ns1:getTempResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Return a double 71.0 which represents the temperature

  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. 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. EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Example <?xml version=‘1.0’ encoding=‘UTF-8’?> <SOAP-ENV:Envelope : <SOAP-ENV:Header> : </SOAP-ENV:Header> : <SOAP-ENV:Body> : <SOAP-ENV:Fault> : : </SOAP-ENV:Fault> : </SOAP-ENV:Body> </SOAP-ENV:Envelope> Envelope: Mandatory Body: Mandatory Header: Optional Fault: Optional

  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 Namespace for SOAP 1.1 <SOAP-ENV:Envelope xmlns:SOAP-ENV= “http://schemas.xmlsoap.org/soap/envelope/” : </SOAP-ENV:Envelope>

  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 Define the namespace of SOAP-ENV is <SOAP-ENV:Envelope xmlns:SOAP-ENV= “http://schemas.xmlsoap.org/soap/envelope/” : </SOAP-ENV:Envelope> Define also element Envelope is part of namespace SOAP-ENV Attribute for defining namespace

  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. 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> • 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. EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction <?xml version=‘1.0’ encoding=‘UTF-8’?> <SOAP-ENV:Envelope : <SOAP-ENV:Header> : </SOAP-ENV:Header> : <SOAP-ENV:Body> : <SOAP-ENV:Fault> : : </SOAP-ENV:Fault> : </SOAP-ENV:Body> </SOAP-ENV:Envelope> Header • Optional. For specifying additional application-level requirements • For example: (1) specify a digital signature; (2) specify an account number

  17. EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction <?xml version=‘1.0’ encoding=‘UTF-8’?> <SOAP-ENV:Envelope : <SOAP-ENV:Header> : </SOAP-ENV:Header> : <SOAP-ENV:Body> : <SOAP-ENV:Fault> : : </SOAP-ENV:Fault> : </SOAP-ENV:Body> </SOAP-ENV:Envelope> Body • Mandatory to all SOAP messages • Carry the actual content such as the RPC requests or responses

  18. EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction <?xml version=‘1.0’ encoding=‘UTF-8’?> <SOAP-ENV:Envelope : <SOAP-ENV:Header> : </SOAP-ENV:Header> : <SOAP-ENV:Body> : <SOAP-ENV:Fault> : : </SOAP-ENV:Fault> : </SOAP-ENV:Body> </SOAP-ENV:Envelope> Fault • In case of error, the body element should contain a fault sub-element • Indicate the error code and the possible cause of error

  19. EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction • May contain the following elements

  20. EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction • For example <SOAP-ENV:Fault> <faultcode xsi:type="xsd:string"> SOAP-ENV:Client</faultcode> <faultstring xsi:type="xsd:string"> 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. </faultstring> </SOAP-ENV:Fault>

  21. EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction • Samples of fault codes

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

  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. 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]”> <item xsi:type="xsd:double">54.99</item> <item xsi:type="xsd:double">19.99</item> </return> Specify the type is array and there are two double numbers in the array

  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 Accessor names <return xmlns:ns2="urn:examples" xsi:type="ns2:product"> <name xsi:type="xsd:string"> Red Hat Linux</name> <price xsi:type="xsd:double">54.99</price> <description xsi:type="xsd:string"> Red Hat Linux Operating System </description> <SKU xsi:type="xsd:string">A358185</SKU> </return>

  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. EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction Specify the encoding style SOAP-ENV:encodingStyle= "http://xml.apache.org/xml-soap/literalxml"> <return> <product sku="A358185"> <name>Red Hat Linux</name> <description>Red Hat Linux Operating System</description> <price>54.99</price></product> </return> Doing the same as the struct example but without the SOAP rules. Solely in generic XML format

  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. 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. EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction SOAP Interoperability • Although SOAP was developed to solve the interoperability problem when doing RPC, it also has interoperabilityproblem • 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. 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

More Related