SOAP and REST - University of California, Irvine

fortnecessityusefulDéveloppement de logiciels

14 déc. 2013 (il y a 3 années et 9 mois)

99 vue(s)

SOAP and REST

Presented by

Ranga Raj

References


Web Services (
Concepts, Architectures and
Applications
)
by Alonso,
Casati
,
Kuno
,
Machiraju


Distributed Systems (
Concepts and Design
)
by
Coulouris
,
Dollimore

and
Kindberg


http://www.ajaxonomy.com/2008/xml/web
-
services
-
part
-
1
-
soap
-
vs
-
rest


Wikipedia articles on SOAP and REST


Internet


Search for SOAP and REST differences


e.g. Stackoverflow.com, rest.elkstein.org

What is SOAP?


S
imple
O
bject
A
ccess
P
rotocol


Originally conceived as the minimal possible infrastructure
necessary to perform RPC through the Internet


Need to work across firewalls


Uses a very simple message structure


Transported between systems via HTTP (or SMTP or UDP)


Uses an XML format


Designed to support loosely
-
coupled applications using
asynchronous messages


A protocol that implements an RPC interaction pattern by
communicating using SOAP messages


Current version of SOAP is version 1.2


Released in 2007

WSDL of the

Service Provider


WSDL Compiler

(Client)

WSDL Compiler

(Server)

Application Object

(Client)

Stub

SOAP
-
based

Middleware

Application Object

(Service Provider)

Skeleton

SOAP
-
based

Middleware

Service Requestor
(Client)

Service Provider

SOAP Messages

Where does SOAP fit in?

SOAP Message structure

SOAP Envelope

SOAP Header

header block

SOAP Body

body block


Optional


Contains information needed for
the ‘intermediary’ nodes


Contains contextual information
indentifying the client


Transaction context is specified
here


Mandatory


Contains the message from
‘sender’ to the ultimate ‘receiver’


Method to be invoked and the
parameters as a ‘request’


‘Response’ to the ‘request’


SOAP Interaction styles

SOAP Envelope

SOAP Body

PurchaseOrderDoc

-
itemCode

-
quantity

SOAP Envelope

SOAP Body

AcknowledgementDoc

-
orderId

SOAP Envelope

SOAP Body

methodName

orderGoods

SOAP Envelope

SOAP Body

methodReturn

inputParam1
itemCode

inputParam2
quantity

returnValue

orderId

Document Style interaction

RPC
-

Style interaction

©Gustavo Alonso, ETH Zürich.

SOAP Envelope














SOAP

header




Transactional

context

SOAP

Body







Input parameter 1

Input parameter 2

Name of Procedure

HTTP POST

SOAP Envelope











SOAP

header




Transactional

context

SOAP

Body




Return parameter

HTTP Acknowledgement

SERVICE REQUESTER

SERVICE PROVIDER

RPC call

HTTP engine

SOAP

engine

Procedure

HTTP engine

SOAP

engine

Implementation of SOAP

Client Stub

Service Requestor

Client Implementation

SOAP Engine

HTTP Engine

Invokes the service


as a local call

Invoke the SOAP Engine to

prepare a SOAP message

Packages SOAP into HTTP and

passes it to an HTTP client that

sends it to the provider

Server Stub

Service Provider

Service Implementation

SOAP Engine

HTTP Engine

Invokes the local procedure

of the service implementation

The router parses the message

identifies the appropriate stub,

and delivers the parsed message

Passes the content of the

HTTP message to the router

Advantages and Disadvantages of SOAP


Advantages


Simple and Portable (XML Format)


Goes across Firewalls (typically using HTTP and SMTP)


Open Standards


Loose Coupling between applications


Interoperable (portable across languages incl. Java, C, C++, Python, C# and
many more)


Adheres to an RPC model in the implementation


Well
-
described using WSDL at design
-
time


Easy to consume


Disadvantages


Statelessness


Very much tied to HTTP POST message


Needed programmer discipline to use other HTTP verbs like GET, PUT or DELETE


At some level requires programmers to know the underlying transport
mechanism


Rigid type
-
checking during development time


Requires design tools

What is REST?


Re
presentational
S
tate
T
ransfer


An approach where clients use URLs


Can use HTTP verbs like GET, POST, PUT or DELETE


Clients are manipulate the state (CRUD) of the resource


via the
url

of the resource


No formal directory of such services


Message Format mutually agreed or specified by provider


Very simple message structure


Primary motivation, architecture for:


scalability of component interactions


generality of interfaces


independent deployment of components, and intermediary
components to reduce interaction latency


enforce security


encapsulate legacy systems

REST
-

explained

"
Representational State Transfer
is intended to evoke an
image of how a well
-
designed Web application behaves:
a
network of web pages

(a virtual state
-
machine), where the
user progresses through an application by selecting links (
state
transitions
), resulting in the next page (
representing the next
state of the application
) being transferred to the user and
rendered for their use.“


Roy Fielding



Fielding, Roy Thomas (2000), Architectural Styles and the
Design of Network
-
based Software Architectures, Doctoral
dissertation, University of California, Irvine

Advantages and Disadvantages of REST


Advantages


Portable like SOAP


Much simpler than SOAP


Less reliance on Tools


Every resource has a unique URL


Uses the power of HTTP (POST, GET, PUT, DELETE) to operate
on the resource


Lightweight, no extra XML markup


Disadvantages


Ideal for point
-
to
-
point interaction between systems


No support for security, policy, reliable messaging


Tied to the HTTP transport model

SOAP and REST compared


SOAP (is a protocol)


A typical service endpoint:
http://location/CustomerService.svc




The corresponding WSDL location:
http://location/CustomerService.svc?wsdl



WSDL is detailed to the point of being complex named messages, bindings, ports, parts,
input and output operations, etc.


SOAP services are simply HTTP POSTs to the same endpoint where each
payload is wrapped inside the body of a ‘SOAP’ envelope.


REST (is an architectural style)


HTTP GET on URL
http://location/customers


returns a list of customers


GET on
http://location/customers/mycust/orders



would return all of

mycust
’ orders


GET
http://location/customers/mycust



would return details about the
customer ‘
mycust



Access to different operations on the same resources via the other HTTP
methods: POST, PUT and DELETE


POST on URL
http://location/customers


appends a Customer to the list of
customers

Questions