web services: principles & technology by mike p. papazoglou and w3schools (brought to you by m....

34
Web Services: Principles & Technology By Mike P. Papazoglou http://www.perfectxml.com/SOAPTutorial .asp and W3Schools (brought to you by M. Vavalis) Simple Object Access Protocol

Upload: eustace-wood

Post on 24-Dec-2015

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

Web

Serv

ices:

Pri

nci

ple

s &

Tech

nolo

gy

By Mike P. Papazoglou http://www.perfectxml.com/SOAPTutorial.aspand W3Schools(brought to you by M. Vavalis)

Simple Object Access Protocol

Page 2: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

Simple Object Access Protocol

Slides from M. Papazoglou, W3Schools

http://www.perfectxml.com/SOAPTutorial.aspand other sources

brought to you by M. Vavalis

2

Page 3: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

Inter-Application Communication

• Conventional distributed applications• CORBA, DCOM, Java/RMI, are

• based on Object RPC (ORPC) protocols • attempted to marry object orientation and network protocols

• Weaknesses • Both ends of the communication link would need to be implemented under

the same distributed object model (Java/RMI or CORBA/IIOP )• difficulty of getting these protocols to work over firewalls or proxy servers

• most firewalls are configured to allow HTTP to pass across, but not IIOP.

To address the problem of overcoming proprietary systems running on heterogeneous infrastructures, web services rely on SOAP, an XML-based communication protocol for exchanging messages between computers regardless of their operating systems or programming environment.

3

Page 4: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

What is SOAP?

• Standard messaging protocol used by Web services. • SOAP’s primary application is inter-application

communication. • Codifies the use of XML as an encoding scheme for request

& response parameters using HTTP as a means for transport.

4

Page 5: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

What is SOAP?

• A message format for one-way communication describing how a message can be packed into an XML document

• A description of how a SOAP message should be transported using HTTP, SMTP or FTP (for legacy applications)

• A set of rules that must be followed when processing a SOAP message

• a simple classification of the entities involved in processing a SOAP message.

• A set of conventions on how to turn an RPC call into a SOAP message and back.

5

Page 6: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

SOAP as a lightweight protocol

• The SOAP protocol possesses only two properties. It can :1. send and receive HTTP (or other) transport protocol packets, and 2. process XML messages.

• This can be contrasted with the heavyweight protocols such as ORPC protocols.

6

Page 7: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

Distributed Application Processing

7

Web-serviceimplementationinfrastructure

Web-serviceprovider

3

4

Web-servicerequester

1 6

ClientApplication

SOAP messageXML document

Network Transport Protocol(HTTP)

5

Web-serviceApplication

SOAPserver

Network Transport Protocol(HTTP)

2

firewall

Page 8: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

SOAP in One Slide

• SOAP is just a message format.• Must transport with HTTP, TCP, etc.

• SOAP is independent of but can be connected to WSDL.• SOAP provides rules for processing the message as it passes through

multiple steps.• SOAP payloads

• SOAP carries arbitrary XML payloads as a body.• SOAP headers contain any additional information• These are encoded using optional conventions

Page 9: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

A simple SOAP message

9

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body> <helloWorld/> </Body></Envelope>

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body> <helloWorld xmlns="http://www.soapware.org/"/> </Body></Envelope>

<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP:Body> <m:helloWorld xmlns:m="http://www.soapware.org/"/> </SOAP:Body></SOAP:Envelope>

Page 10: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

SOAP messages

<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP:Body> <m:getCountryName xmlns:m="http://www.soapware.org/"> <statenum>GR</statenum> </m:getStateName> </SOAP:Body></SOAP:Envelope>

10

Page 11: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

SOAP messages

<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP:Body> <m:getCountryName xmlns:m="http://www.soapware.org/"> <statenum>GR</statenum> <format>abbreviation</format> </m:getStateName> </SOAP:Body></SOAP:Envelope>

11

Page 12: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

SOAP messages

• based on message exchanges.• Messages are seen as envelopes where the

application encloses the data to be sent.• Consist of an <Envelope> element containing

an optional <Header> and a mandatory <Body> element.

• The contents of these elements are application defined and not a part of the SOAP specifications.

• <Header> contains blocks of information relevant to how the message is to be processed. This helps pass information in SOAP messages that is not application payload.

• <Body> is where the main end-to-end information conveyed in a SOAP message must be carried.

12

<Envelope><Envelope>

0..1

1..*

<Header><Header> <Body><Body>

1

<Headerblock>

<Headerblock>

<Bodyentry>

<Bodyentry>

1..*

<Envelope><Envelope>

0..1

1..*

<Header><Header> <Body><Body><Header><Header> <Body><Body>

1

<Headerblock>

<Headerblock>

<Bodyentry>

<Bodyentry>

<Headerblock>

<Headerblock>

<Bodyentry>

<Bodyentry>

1..*

SOAP envelope

SOAP header

header block

SOAP body

body block

Page 13: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

13

<env:Envelope xmlns:env=“http://www.w3.org/2003/05/soap-envelope” env:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/”> ……</env:Envelope>

<env:Envelope xmlns:env=“http://www.w3.org/2003/05/soap-envelope” > … <env:Header> <tx:transaction-id xmlns:tx=”http://www.transaction.com/transaction”

env:mustUnderstand=”true”> 512 </tx:transaction-id> <notary:token xmlns:notary=”http://www.notarization-services.com/token” env:mustUnderstand=”true”> GRAAL-5YF3 </notary:token> </env:Header>

……………</env:Envelope>

Example of SOAP envelope

Example of SOAP header

Page 14: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

SOAP intermediaries

• SOAP headers have been designed in anticipation of participation of other SOAP processing nodes - called SOAP intermediaries - along a message's path from an initial SOAP sender to an ultimate SOAP receiver.

• A SOAP message travels along the message path from a sender to a receiver.

• All SOAP messages start with the initial sender, which creates the SOAP message, and end with the ultimate receiver.

14

Initial Sender

IntermediaryNode

Ultimate Receiver

SignatureValidationServiceNode

SignatureValidationServiceNode

PurchasingServiceNode

PurchasingServiceNode

CustomerNode

CustomerNode

1

23

Submit digitally signed purchase order

Validate digital signature

Process purchase order

Page 15: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

15

<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env=“http://www.w3.org/2003/05/soap-envelope”> <env:Header> <m:order xmlns:m="http://www.plastics_supply.com/purchase-order" env:role="http://www.w3.org/2003/05/soap-envelope/role/next" env:mustUnderstand="true"> <m:order-no >uuid:0411a2daa</m:order-no> <m:date>2004-11-8</m:date> </m:order> <n:customer xmlns:n="http://www.supply.com/customers" env:role="http://www.w3.org/2003/05/soap-envelope/role/next" env:mustUnderstand="true"> <n:name> Marvin Sanders </n:name> </n:customer > </env:Header> <env:Body> <-- Payload element goes here --> </env:Body></env:Envelope>

Page 16: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

SOAP Body

• The area of the SOAP message containing the application specific XML data (payload) to be exchanged in the message.

• Must be present and is an immediate child of the envelope. • It may contain

• a number of child elements, called body entries, • nothing

• Contains either:• Application-specific data • A fault message only when an error occurs. • NOT BOTH

16

Page 17: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

<?xml version='1.0' ?>

<env:Envelope xmlns:env="http://www.w3.org/2002/06/soap-envelope" >

<env:Header> <t:transactionID xmlns:t="http://intermediary.example.com/procurement" env:role="http://www.w3.org/2002/06/soap-envelope/role/next" env:mustUnderstand="true" > 57539 </t:transactionID> </env:Header>

<env:Body> <m:orderGoods env:encodingStyle="http://www.w3.org/2002/06/soap-encoding" xmlns:m="http://example.com/procurement"> <m:productItem> <name>SEnergy mimic board</name> </m:productItem> <m:quantity> 35 </m:quantity> </m:orderGoods> </env:Body>

</env:Envelope>

Example

17

Page 18: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

The SOAP Communication Model• Supports two possible communication styles:

• remote procedure call (RPC) and • document (or message).

18

Price for given product

Price for given product

Onlineprice

response

Onlineprice

response

Application programs Database

Web servicesdefinitions

Price for given product

Price for given product

Onlineprice

response

Onlineprice

response

Application programs Database

Price for given product

Price for given product

Onlineprice

response

Onlineprice

response

Application programs Database

Web servicesdefinitions Request

for quote

Request for

quote

Quotedocument

Quotedocument

Web Service Definitions

Business Process Flow

Receive

Check

Send

Database

Request for

quote

Request for

quote

Quotedocument

Quotedocument

Web Service Definitions

Business Process Flow

Receive

Check

SendSend

Database

RPC-style interaction Document-style interaction

Page 19: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

PRC-style SOAP Services

• A remote procedure call (RPC)-style Web service appears as a remote object to a client application. The interaction between a client and an RPC-style Web service centers around a service-specific interface. Clients express their request as a method call with a set of arguments, which returns a response containing a return value.

19

SOAP envelope

SOAP body

method nameorderGoods

input parameter 1product item

input parameter 2quantity

SOAP envelope

SOAP body

method return

return valueorder id

Page 20: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

20

<env:Envelope xmlns:SOAP=“http://www.w3.org/2003/05/soap-envelope” xmlns:m="http://www.plastics_supply.com/product-prices"> <env:Header>

<tx:Transaction-id xmlns:t=”http://www.transaction.com/transactions”

env:mustUnderstand='1'> 512

</tx:Transaction-id> </env:Header> <env:Body>

<m:GetProductPrice> <product-id> 450R6OP </product-id ></m:GetProductPrice >

</env:Body></env:Envelope>

<env:Envelope xmlns:SOAP=“http://www.w3.org/2003/05/soap-envelope” xmlns:m="http://www.plastics_supply.com/product-prices"> <env:Header>

<--! – Optional context information --> </env:Header> <env:Body>

<m:GetProductPriceResponse> <product-price> 134.32 </product-price></m:GetProductPriceResponse>

</env:Body></env:Envelope>

Example of RPC-style SOAP body

Example of RPC-style SOAP response message

Page 21: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

Document (Message)-style SOAP Services

• In the document-style of messaging, the SOAP <Body> contains an XML document fragment. The <Body> element reflects no explicit XML structure.

• The SOAP run-time environment accepts the SOAP <Body> element as it stands and hands it over to the application it is destined for unchanged. There may or may not be a response associated with this message.

21

SOAP envelope

SOAP body

PurchaseOrderdocument

- product item- quantity

SOAP envelope

SOAP body

Acknowledgementdocument- order id

Page 22: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

Example of document-style SOAP body

22

<env:Envelope xmlns:SOAP=“http://www.w3.org/2003/05/soap-envelope”> <env:Header>

<tx:Transaction-id xmlns:t=”http://www.transaction.com/transactions”

env:mustUnderstand='1'> 512 </env:Header> <env:Body> <po:PurchaseOrder oderDate=”2004-12-02” xmlns:m="http://www.plastics_supply.com/POs"> <po:from> <po:accountName> RightPlastics </po:accountName>

<po:accountNumber> PSC-0343-02 </po:accountNumber> </po:from> <po:to> <po:supplierName> Plastic Supplies Inc. </po:supplierName> <po:supplierAddress> Yara Valley Melbourne </po:supplierAddress> </po:to> <po:product> <po:product-name> injection molder </po:product-name> <po:product-model> G-100T </po:product-model> <po:quantity> 2 </po:quantity> </po:product>

</ po:PurchaseOrder > </env:Body></env:Envelope>

Page 23: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

SOAP Fault element• SOAP provides a

model for handling faults arise.

• It distinguishes between the conditions that result in a fault, and the ability to signal that fault to the originator of the faulty message or another node. The SOAP <Body> is the place where fault information is placed.

23

<env:Envelope xmlns:SOAP=“http://www.w3.org/2003/05/soap-envelope” xmlns:m="http://www.plastics_supply.com/product-prices"> <env:Header>

<tx:Transaction-id xmlns:t=”http://www.transaction.com/transactions” env:mustUnderstand='1'> 512

</tx:Transaction-id> </env:Header> <env:Body> <env:Fault> <env:Code> <env:Value>env:Sender</env:Value> <env:Subcode> <env:Value> m:InvalidPurchaseOrder </env:Value> </env:Subcode> </env:Code> <env:Reason> <env:Text xml:lang="en-UK"> Specified product did not exist </env:Text> </env:Reason> <env:Detail> <err:myFaultDetails xmlns:err="http://www.plastics_supply.com/faults"> <err:message> Product number contains invalid characters </err:message> <err:errorcode> 129 </err:errorcode> </err:myFaultDetails> </env:Detail> </env:Fault> </env:Body></env:Envelope>

Page 24: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

SOAP and HTTP

• A binding of SOAP to a transport protocol is a description of how a SOAP message is to be sent using that transport protocol

• The typical binding for SOAP is HTTP• SOAP can use GET or POST. With GET, the

request is not a SOAP message but the response is a SOAP message, with POST both request and response are SOAP messages (in version 1.2, version 1.1 mainly considers the use of POST).

• SOAP uses the same error and status codes as those used in HTTP so that HTTP responses can be directly interpreted by a SOAP module

24

SOAP EnvelopeSOAP Envelope

SOAP header

Transactionalcontext

SOAP Body

Input parameter 1

Input parameter 2

Name of Procedure

HTTP POST

Page 25: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

RPC call using SOAP over HTTP

25

service provider

SOAP engine

service implementation (other tiers)

HTTP engine

service requestor

HTTP engine

client implementation (other tiers)

SOAP engine

SOAP envelope

SOAP header

transactional context

SOAP body

name of the procedure

input parameter 1

input parameter 2

HTTP Post

SOAP envelope

SOAP header

transactional context

SOAP body

return parameter

SOAP envelope

SOAP header

transactional context

SOAP body

return parameter

HTTP Post

Page 26: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

SOAP extensions and libraries

• ASP.NET• Python• PHP• C, C++, Java

26

Page 27: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

Where are the servlets?What’s wrong with XML over HTTP?

27

Page 28: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

Example - Travel reservation service

• define a set of XML documents, and a choreography—or protocol—of how those messages pass between the service and its client.

• have XML messages corresponding to a schedule and price inquiry, a reservation request, a confirmation, and a final itinerary.

• You can define • the structure and possible values of those XML messages with XML schema. • the reservation protocol with XML as well, perhaps using an XML-based Web

service choreography language.

• Write a servlet that • listens for incoming messages, • routes those messages to a message processor component—(e.g. EJB) • returns the results to the caller.

28

Page 29: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

What’s wrong with XML over HTTP?

29

Page 30: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

<?xml version='1.0'?><reservation> <code> 12345 </code> <o:creditCard xmlns:o="http://mycompany.example.com/financial"> <n:name xmlns:n="http://mycompany.example.com/employees">

John Galt </n:name> <o:number> 123456789099999 </o:number> <o:expiration> 2005-02 </o:expiration> </o:creditCard></reservation>

30

XL over HTTP messages

Page 31: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

<?xml version='1.0' ?><env:Envelope xmlns:env="http://www.w3.org/2002/12/soap-envelope"> <env:Header> <m:reservationCharge xmlns:m="http://travelcompany.example.org/reservation" env:role="http://www.w3.org/2002/12/soap-envelope/role/next" env:mustUnderstand="true">

<m:reference>12345</m:reference> <m:dateAndTime>2003-03-09T14:00:00.000-09:00</m:dateAndTime> </m:reservationCharge></env:Header><env:Body> <r:reservationCharge xmlns:p="http://travelcompany.example.org/reservation"> <r:code> 12345 </r:code> <o:creditCard xmlns:o="http://mycompany.example.com/financial"> <n:name xmlns:n="http://mycompany.example.com/employees">

John Galt </n:name> <o:number> 123456789099999 </o:number> <o:expiration> 2005-02 </o:expiration> </o:creditCard> </r:reservationCharge> </env:Body></env:Envelope>

31

Document-style SOAP message

Page 32: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

RPC-style SOAP message

<?xml version='1.0' ?><env:Envelope xmlns:env="http://www.w3.org/2002/12/soap-envelope"><env:Header> <t:transaction xmlns:t="http://thirdparty.example.org/transaction" env:encodingStyle="http://example.com/encoding" env:mustUnderstand="true" >5</t:transaction> </env:Header> <env:Body> <m:chargeReservation env:encodingStyle="http://www.w3.org/2002/12/soap-encoding" xmlns:m="http://travelcompany.example.org/"> <m:reservation xmlns:m="http://travelcompany.example.org/reservation"> <m:code>12345</m:code> </m:reservation> <o:creditCard xmlns:o="http://mycompany.example.com/financial"> <n:name xmlns:n="http://mycompany.example.com/employees">

John Galt </n:name> <o:number> 123456789099999 </o:number> <o:expiration> 2005-02 </o:expiration> </o:creditCard> </m:chargeReservation> </env:Body></env:Envelope>

32

Page 33: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

Advantages & disadvantages of SOAP

• Advantages of SOAP are:• Simplicity• Portability• Firewall friendliness• Use of open standards• Interoperability• Universal acceptance

• Disadvantages of SOAP are:• Too much reliance on HTTP• Statelessness• Serialization by value and not by reference

33

Page 34: Web Services: Principles & Technology By Mike P. Papazoglou  and W3Schools (brought to you by M. Vavalis) Simple

SOAP Primary References

• SOAP is defined by a number of links– http://www.w3.org/TR/soap/

• See primarily the “Primer” and “Messaging Framework” links.

• The actual SOAP schema is available from http://www.w3.org/2003/05/soap-envelope/– It is pretty small, as these things go.