SOAP vs REST - PowerPoint PPT Presentation

About This Presentation
Title:

SOAP vs REST

Description:

soap-env:encodingStyle='http://schemas.xmlsoap.org/soap/encoding ... Many other incomprehensible extensions, collectively referred to as WS ... – PowerPoint PPT presentation

Number of Views:851
Avg rating:3.0/5.0
Slides: 21
Provided by: JoeMor9
Category:

less

Transcript and Presenter's Notes

Title: SOAP vs REST


1
SOAP vs REST
  • Dec 7, 2007

Can you read this? If not, please sit closer.
Thank you.
2
XML RPC (1998)
Request lt?xml version"1.0"?gt ltmethodCallgt ltmetho
dNamegtdoSomeWorklt/methodNamegt ltparamsgt ltparamgt ltva
luegtltintgt40lt/intgtlt/valuegt lt/paramgt ltparamgt ltvaluegt
ltdoublegt-12.53lt/doublegtlt/valuegt lt/paramgt lt/paramsgt
lt/methodCallgt Response lt?xml
version"1.0"?gt ltmethodResponsegt ltparamsgt ltparamgt
ltvaluegt ltarraygt ltdatagt ltvaluegtltdateTime.iso8601gt19
980717T140855lt/dateTime.iso8601gtlt/valuegt ltvaluegt
ltstringgtSomething herelt/stringgtlt/valuegt lt/datagt lt/
arraygt lt/valuegt lt/paramgt lt/paramsgt lt/methodRespons
egt
3
Early SOAP (2000) section 5 encoding
lt?xml version"1.0"?gt ltsoap-envenvelope
soap-envencodingStyle"http//schemas.xmlsoap.org
/soap/encoding/" xmlnssoap-env"http//sc
hemas.xmlsoap.org/soap/envelope/"
xmlnssoap-enc"http//schemas.xmlsoap.org/soap/en
coding/" xmlnsxsd"http//www.w3.org/1999
/XMLSchema" xmlnsxsi"http//www.w3.org/1
999/XMLSchema-instance"gt ltsoap-envheadergt ... lt/s
oap-envheadergt ltsoap-envbodygt ltmdoSomeWork
xmlnsm"http//www.lab49.com/"gt ltfoo
xsitype"xsdint"gt40lt/foogt ltbargt-12.53lt/bargt lt/m
doSomeWorkgt lt/soap-envbodygt lt/soap-envenvelopegt
lt?xml version"1.0"?gt ltsoap-envEnvelope
soap-envencodingStyle"http//schemas.xmlsoap.or
g/soap/encoding/" xmlnssoap-env"http//s
chemas.xmlsoap.org/soap/envelope/"
xmlnssoap-enc"http//schemas.xmlsoap.org/soap/en
coding/" xmlnsxsd"http//www.w3.org/1999
/XMLSchema" xmlnsxsi"http//www.w3.org/1
999/XMLSchema-instance"gt ltsoap-envbodygt ltmdoSome
WorkResponse xmlnsm"http//www.lab49.com/"gt ltsoa
p-encarray soap-encarrayType"xsdur-type2"gt lt
baz xsitype"xsdint"gt12345lt/bazgt ltquux
xsitype"xsdstring"gtSomething
herelt/quuxgt lt/soap-encarraygt lt/mdoSomeWorkRespon
segt lt/soap-envBodygt lt/soap-envEnvelopegt
4
SOAP fancy encoding rules
References
lteBookgt lttitlegtMy Life and Worklt/titlegt ltauthor
 href"Person-1"/gtlt/eBookgt ltePerson id"Perso
n-1"gt ltnamegtHenry Fordlt/namegt ltaddress href"Ad
dress-2"/gtlt/ePersongt lteAddress id"Address-2"gt
 ltemailgtmailtohenryford_at_hotmail.comlt/emailgt ltw
ebgthttp//www.henryford.comlt/webgtlt/eAddressgt
Sparse arrays
ltSOAP-ENCArray SOAP-ENCarrayType"xsdstring,
4"gt ltSOAP-ENCArray href"array-1"
SOAP-ENCposition"2"/gtlt/SOAP-ENCArraygt ltSOAP
-ENCArray id"array-1" SOAP-ENCarrayType"xsdst
ring10,10"gt ltitem SOAP-ENCposition"2,2"gtThi
rd row, third collt/itemgt ltitem
SOAP-ENCposition"7,2"gtEighth row, third
collt/itemgtlt/SOAP-ENCArraygt
5
Document/literal (2003) Forget all the fancy
encoding rules
lt?xml version"1.0"?gt ltsoap-envenvelope
soap-envencodingStyle"http//schemas.xmlsoap.org
/soap/encoding/" xmlnssoap-env"http//sc
hemas.xmlsoap.org/soap/envelope/"
xmlnsxsd"http//www.w3.org/1999/XMLSchema"
xmlnsxsi"http//www.w3.org/1999/XMLSchema-ins
tance"gt ltsoap-envheadergt ... lt/soap-envheadergt lt
soap-envbodygt your XML Schema compliant
document goes here lt/soap-envbodygt lt/soap-enve
nvelopegt
6
I want my, I want my RPC (rpc/literal)
lt?xml version"1.0"?gt ltsoap-envenvelope
soap-envencodingStyle"http//schemas.xmlsoap.org
/soap/encoding/" xmlnssoap-env"http//sc
hemas.xmlsoap.org/soap/envelope/"
xmlnssoap-enc"http//schemas.xmlsoap.org/soap/en
coding/" xmlnsxsd"http//www.w3.org/1999
/XMLSchema" xmlnsxsi"http//www.w3.org/1
999/XMLSchema-instance"gt ltsoap-envheadergt ... lt/s
oap-envheadergt ltsoap-envbodygt ltmdoSomething
xmlnsmhttp//lab49.com/gt ltfoogt XML Schema
compliant value XML Schema compliant
value lt/foogt ltbargt XML Schema compliant
value lt/bargt lt/mdoSomethinggt lt/soap-envbodygt
lt/soap-envenvelopegt
Namespace does not have to be the same as the
parameter values
Argument elements dont even have a namespace
Lets you model procedure calls, but cant
validate SOAP body with an XML Schema
7
SOAP encoding convention line-up circa 2003
  • RPC/encoded (the original)
  • Document/literal (based on XML Schema, but
    doesnt model RPC)
  • RPC/literal (adds RPC modeling, breaks XML Schema
    validation)
  • Cant we model RPC without breaking Schema
    validation?

8
Wrapped document literal style (2005)
lt?xml version"1.0"?gt ltsoap-envenvelope
soap-envencodingStyle"http//schemas.xmlsoap.org
/soap/encoding/" xmlnssoap-env"http//sc
hemas.xmlsoap.org/soap/envelope/"
xmlnssoap-enc"http//schemas.xmlsoap.org/soap/en
coding/" xmlnsxsd"http//www.w3.org/1999
/XMLSchema" xmlnsxsi"http//www.w3.org/1
999/XMLSchema-instance"gt ltsoap-envheadergt ... lt/s
oap-envheadergt ltsoap-envbodygt ltmdoSomething
xmlnsmhttp//lab49.com/gt ltmfoogt lt/mfoogt ltm
bargt lt/mbargt lt/mdoSomethinggt lt/soap-envbodygt
lt/soap-envenvelopegt
Entire body complies with an XML
Schema containing element doSomething
containing a sequence of elements foo and bar
9
Handy summary
Scheme Rating Why?
rpc/encoded (1998) BAD Because encoded means section 5 encoding and that hairy scheme has been displaced by XML Schemas
doc/literal (2003) BEST Send an XML Schema compliant document, get one back. Awesome.
rpc/literal (2003) BAD Failed attempt to reconcile document style with RPC.
wrapped/literal (2005) GOOD Successful attempt to reconcile document style with RPC.
10
Web Service Definition Language (WSDL 1.1)
ltdefinitionsgt lttypesgt ltschemagt ltelement
name"doSomething"gt ltcomplexTypegt ltsequencegt ltelem
ent name"foo" nillable"true" type"string"
/gt ltelement name"bar" nillable"true"
type"double" /gt lt/sequencegt lt/complexTypegt lt/elem
entgt ltelement name"doSomethingResponse"gt ... lt/el
ementgt lt/schemagt lt/typesgt ltmessage
name"doSomethingRequest"gt ltpart
name"parameters" element"doSomething"gtlt/partgt
lt/messagegt ltmessage name"doSomethingResponse"gt
ltpart name"parameters" element"doSomethingRespon
se"gtlt/partgt lt/messagegt ltportType
name"myServices"gt ltoperation name"doSomething"gt
ltinput name"doSomethingRequest"
message"doSomethingRequest"gtlt/inputgt ltoutput
name"doSomethingResponse" message"doSomethingRes
ponse"gtlt/outputgt lt/operationgt lt/portTypegt ltbindin
g name"myServicesHttpBinding" type"myServices"gt
ltbinding style"document" transport"http//schema
s.xmlsoap.org/soap/http" /gt ltoperation
name"doSomething"gt ltoperation soapAction""
/gt ltinput name"doSomethingRequest"gt ltbody
use"literal" /gt lt/inputgt ltoutput
name"doSomethingResponse"gt ltbody use"literal"
/gt lt/outputgt lt/operationgt lt/bindinggt ltservice
name"myServices"gt ltport name"myServicesHttpPort"
binding"myServicesHttpBinding"gt ltaddress
location"http//..." /gt lt/portgt lt/servicegt lt/def
initionsgt
Wrapped style. Notice the operation has one
message part called parameters which is an XML
sequence of the args
11
WSDL IS IMPORTANT
12
Code first / WSDL first decision algorithm
Write code first and use doc/literal style. i.e.
Every method has one arg. Use annotations to name
everything and review WSDL afterward.
Will other projects be using these services? i.e.
is this part of an SOA?
Are you in a great hurry?
No
No
Yes
Yes
Write code first in wrapped/literal style, i.e.
Use annotations to name everything and review
WSDL afterward.
Write WSDL first. Think through interfaces
carefully, plan for backward compatibility, write
lots of comments, and maintain in source control.
13
Goodies
  • WS-Security (message integrity,
    confidentiality, and authentication)
  • WS-ReliableMessaging
  • WS-Routing (messaging patterns and routes)
  • WS-Eventing (pub/sub)
  • Many other incomprehensible extensions,
    collectively referred to as WS-

14
The SOAP way of thinking
15
In the meantime
16
Will SOAP collapse under its own weight?
17
Complexity
Low
High
SOAP
?
REST
18
Comparison points
  • WSDL is a good idea for both SOAP and REST
  • (not a long-term differentiator)
  • SOAP and REST both allow you to name
    resources with URIs
  • (also not a long-term differentiator)
  • REST adds value to the entire web
  • (we dont care)
  • REST is easier to program
  • (not for long)
  • SOAP provides better support for async
    messaging
  • SOAP is better if developers and network
    administrators dont
  • have a good relationship

19
In conclusion
  • For enterprise apps, default to SOAP.
  • But if (like Amazon.com) you
  • are catering to people who are not making a large
  • investment in connecting to your service
  • have control over your network
  • are trying to reach a broad audience
  • then go with REST.
  • Expires Mon, 31 Mar 2008 200000 GMT

20
Questions?
Write a Comment
User Comments (0)
About PowerShow.com