eie424 distributed systems and networking programming –part ii

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

Upload: maxima

Post on 06-Jan-2016

27 views

Category:

Documents


0 download

DESCRIPTION

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?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: EIE424 Distributed Systems and Networking Programming –Part II

1

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

3.1 SOAP – Introduction

Page 2: EIE424 Distributed Systems and Networking Programming –Part II

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 II3.1 SOAP – Introduction

Page 3: EIE424 Distributed Systems and Networking Programming –Part II

3

EIE424

Distributed Systems and Networking Programming –Part II3.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 messagesData 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)

Page 4: EIE424 Distributed Systems and Networking Programming –Part II

4

SOAP vs XML-RPCSimilarities

– 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 II3.1 SOAP – Introduction

Page 5: EIE424 Distributed Systems and Networking Programming –Part II

5

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

SOAP in Action

SOAPclient

SOAPclient

SOAPserver

SOAPserver

XML

XML

HTTP

HTTPSOAP Response

SOAP Request

Hence SOAP messages can be delivered via the Web

Page 6: EIE424 Distributed Systems and Networking Programming –Part II

6

EIE424

Distributed Systems and Networking Programming –Part II3.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

Page 7: EIE424 Distributed Systems and Networking Programming –Part II

7

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

<?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>

<?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>

A Sample Request in RPC Style

Try to call the remote method getTemp with input parameter, a zipcode: 10016

Page 8: EIE424 Distributed Systems and Networking Programming –Part II

8

EIE424

Distributed Systems and Networking Programming –Part II3.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>

<?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

Page 9: EIE424 Distributed Systems and Networking Programming –Part II

9

EIE424

Distributed Systems and Networking Programming –Part II3.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

Page 10: EIE424 Distributed Systems and Networking Programming –Part II

10

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

Message Structure

SOAP Message

Envelope (mandatory)

Header (optional)

Body (mandatory)

Fault (optional)

Page 11: EIE424 Distributed Systems and Networking Programming –Part II

11

EIE424

Distributed Systems and Networking Programming –Part II3.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>

<?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

Envelope: Mandatory

Body: Mandatory

Fault: Optional

Example

Page 12: EIE424 Distributed Systems and Networking Programming –Part II

12

EIE424

Distributed Systems and Networking Programming –Part II3.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>

<SOAP-ENV:Envelope xmlns:SOAP-ENV= “http://schemas.xmlsoap.org/soap/envelope/” :</SOAP-ENV:Envelope>

Namespace for SOAP 1.1

Page 13: EIE424 Distributed Systems and Networking Programming –Part II

13

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

XML NamespacesXML document can define its own markup

language or vocabulariesXML uses namespace to uniquely identify XML

vocabularies

<SOAP-ENV:Envelope xmlns:SOAP-ENV= “http://schemas.xmlsoap.org/soap/envelope/” :</SOAP-ENV:Envelope>

<SOAP-ENV:Envelope xmlns:SOAP-ENV= “http://schemas.xmlsoap.org/soap/envelope/” :</SOAP-ENV:Envelope>

Define the namespace of SOAP-ENV is

Define also element Envelope is part of namespace SOAP-ENVAttribute for

defining namespace

Page 14: EIE424 Distributed Systems and Networking Programming –Part II

14

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

We do not need to really go to http://schemas.xmlsoap.org/soap/envelope/”

to do anythingSince this URL is unique, the word SOAP-ENV is also

unique in this documentIf 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

Page 15: EIE424 Distributed Systems and Networking Programming –Part II

15

EIE424

Distributed Systems and Networking Programming –Part II3.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>

<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

Page 16: EIE424 Distributed Systems and Networking Programming –Part II

16

Header

EIE424

Distributed Systems and Networking Programming –Part II3.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>

<?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>

• Optional. For specifying additional application-level requirements

• For example: (1) specify a digital signature; (2) specify an account number

Page 17: EIE424 Distributed Systems and Networking Programming –Part II

17

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

Body <?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>

<?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>

• Mandatory to all SOAP messages

• Carry the actual content such as the RPC requests or responses

Page 18: EIE424 Distributed Systems and Networking Programming –Part II

18

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

Fault <?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>

<?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>

• In case of error, the body element should contain a fault sub-element

• Indicate the error code and the possible cause of error

Page 19: EIE424 Distributed Systems and Networking Programming –Part II

19

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

Element name Description

faultCode A text code to indicate the class of error

faultString A human-readable explanation of error

faultActor A text string indicating who caused the fault. Particularly useful when the SOAP message travels a few nodes

detail Carry application-specific error message

May contain the following elements

Page 20: EIE424 Distributed Systems and Networking Programming –Part II

20

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

<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>

<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>

For example

Page 21: EIE424 Distributed Systems and Networking Programming –Part II

21

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

Samples of fault codes

Name Description

SOAP-ENV:VersionMismatch Envelope element includes an invalid namespace

SOAP-ENV:Client Indicate the client request contained an error

SOAP-ENV:Server Indicate the server is unable to process the client request

Page 22: EIE424 Distributed Systems and Networking Programming –Part II

22

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

SOAP Data Encoding A data is just a sequence of 1 and 0To 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

Page 23: EIE424 Distributed Systems and Networking Programming –Part II

23

EIE424

Distributed Systems and Networking Programming –Part II3.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/

Page 24: EIE424 Distributed Systems and Networking Programming –Part II

24

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

<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>

<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>

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/

Page 25: EIE424 Distributed Systems and Networking Programming –Part II

25

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

Compound Types

Compound type data contains multiple valuesCan be further divided into arrays and structsArrays contain multiple values of the same type

– Some implementations support multidimensional arrayStructs contain multiple values, but each element

is specified by a name

Page 26: EIE424 Distributed Systems and Networking Programming –Part II

26

EIE424

Distributed Systems and Networking Programming –Part II3.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>

<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

Page 27: EIE424 Distributed Systems and Networking Programming –Part II

27

EIE424

Distributed Systems and Networking Programming –Part II3.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"> <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>

<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>

Accessor names

Page 28: EIE424 Distributed Systems and Networking Programming –Part II

28

EIE424

Distributed Systems and Networking Programming –Part II3.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 encodingDifferent implementation may have different ways to

encode literal XML documentFor Apache SOAP, need to specify the namespace

http://xml.apache.org/xml-soap/literalxml

Page 29: EIE424 Distributed Systems and Networking Programming –Part II

29

EIE424

Distributed Systems and Networking Programming –Part II3.1 SOAP – Introduction

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>

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

Specify the encoding style

Page 30: EIE424 Distributed Systems and Networking Programming –Part II

30

EIE424

Distributed Systems and Networking Programming –Part II3.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

Page 31: EIE424 Distributed Systems and Networking Programming –Part II

31

EIE424

Distributed Systems and Networking Programming –Part II3.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

Page 32: EIE424 Distributed Systems and Networking Programming –Part II

32

SOAP Interoperability

EIE424

Distributed Systems and Networking Programming –Part II3.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

Page 33: EIE424 Distributed Systems and Networking Programming –Part II

33

EIE424

Distributed Systems and Networking Programming –Part II3.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