simple object access protocol. web services: soap2 why simple object access protocol light weight...
TRANSCRIPT
Simple Object Access Protocol
Web Services: SOAP 2
Why Simple Object Access Protocol
Light weight replacement for complicated distributed object technology
Originally for BizTalk (Microsoft/UserLand/Developmentor)
Now a W3C standard
Based on XML and HTTP
Web Services: SOAP 3
Port vs Web Server
ExternalApplication
ExternalApplication
ExternalApplication
TC
P
InternalService
InternalService
InternalService
Web Services: SOAP 4
Port vs Web Server
ExternalApplication
ExternalApplication
ExternalApplication
TC
P
InternalService
InternalService
InternalService
WebServer
XML
paylo
ad “XML-RPC”
Port 80? SOAP is not restricted to port 80
Web Services: SOAP 5
POST /Temperature HTTP/1.1Host: www.weather.comContent-Type: text/xmlContent-Length: <whatever>SOAPAction: “urn:StockQuote#GetQuote”
<s:Envelope xmlns:s=“http://www.w3.org/2001/06/soap-envelope"><s:Body>
… …</s:Body>
</s:Envelope>
HTTP Header
XML Payload(SOAP request)
Soap Extensions
SOAP over HTTP
Request example
Web Services: SOAP 6
HTTP/1.1 200 OKContent-Type: text/xmlContent-Length: <whatever>
<s:Envelope xmlns:s=“http://www.w3.org/2001/06/soap-envelope"><s:Body>
… …</s:Body>
</s:Envelope>
SOAP over HTTP
Response exampleHTTP Header
XML Payload(SOAP response)
Web Services: SOAP 7
SOAP Example: Request
<soap:Envelope> <soap:Body> <xmlns:m= "http://www.amzn.org/books" /> <m:GetBookPrice> <m:BookName>Fast Food
Nation</m:BookName> </m:GetBookPrice> </soap:Body> </soap:Envelope>
Web Services: SOAP 8
SOAP Example: Response
<soap:Envelope> <soap:Body> <xmlns:m="http://www.amzn.org/books" /> <m:GetBookPriceResponse> <m:Price>34.5</m:Price> </m:GetBookPriceResponse> </soap:Body> </soap:Envelope>
Web Services: SOAP 9
SOAP Example: Error
<soap:Fault> <faultcode>0x800700E</faultcode> <faulstring>Unknown book</faultstring></soap:Fault>
Web Services: SOAP 10
SOAP Message
A SOAP message is contained within an XML “envelope”, complete with a Header and Body
SOAP Envelope
SOAP Header(optional)
SOAP Body“payload”
Web Services: SOAP 11
SOAP Message with Binary Attachments
A SOAP message can also contain binary attachments using MIME encoding
SOAP EnvelopeSOAP Header
(optional)
SOAP Body“payload”
MIME HeaderRoot Body PartMIME Boundary
Body PartMIME Boundary
Attachment
Web Services: SOAP 12
SOAP Structure
Envelope containsHeaderBody
Header is optionalOut-of-band information
such as…Authentication information
Message routesLoggingTransaction flow
Body contains XML body of RPC call
SOAP Envelope
SOAP Header
Header Block
Header Block
. . .
SOAP Body
Body Block
Body Block
. . .
Web Services: SOAP 13
SOAP Example
<?xml version="1.0" encoding="UTF-8" ?><env:Envelope
xmlns:env="http://www.w3.org/2001/09/soap-envelope"> <env:Header> <n:alertcontrol xmlns:n="http://example.org/alertcontrol"> <n:priority>1</n:priority> <n:expires>2001-06-22T14:00:00-05:00</n:expires> </n:alertcontrol> </env:Header> <env:Body> <m:alert xmlns:m="http://example.org/alert"> <m:msg>Pick up Mary at school at 2pm</m:msg> </m:alert> </env:Body> </env:Envelope>
Web Services: SOAP 14
XML Messaging in SOAP
EDI: Electronic Document InterchangeSOAP with EDI: XML documents
“Document style SOAP”
RPC: distributed computing, web services“RPC-style” SOAP: parameters and return
values
Web Services: SOAP 15
<s:Envelope xmlns:s=“http://www.w3.org/2001/06/soap-envelope”><s:Header>
<m:transaction xmlns:m=“soap-transaction” s:mustUnderstand=“true”>
<transactionID>1234</transactionID></transaction>
</s:Header><s:Body>
<n:purchaseOrder xmlns:n=“urn:OrderService”><from><person>Christopher Robin</person>
<dept>Accounting</dept></from><to><person>Pooh Bear</person>
<dept>Honey></dept></to><order><quantity>1</quantity> <item>Pooh Stick</item></order>
</n:purchaseOrder></s:Body>
</s:Envelope>
Purchase Order in Document-Style SOAP
Web Services: SOAP 16
RPC Messages
Typically two messages
SOAP Client SOAP Server
Request Message
Response Message
Web Services: SOAP 17
An RPC-style SOAP Message
public Float getQuote (String symbol);
<s:Envelope xmlns:s=“http://www.w3.org/2001/06/soap-envelope”><s:Header>
<m:transaction xmlns:m=“soap-transaction”s:mustUnderstand=“true”>
<transactionID>1234</transactionID></m:transaction>
</s:Header><s:Body>
<n:getQuote xmlns:n=“urn:QuoteService”><symbol xsi:type=“xsd:string”>
IBM</symbol>
</n:getQuote></s:Body>
</s:Envelope>
Web Services: SOAP 18
SOAP Response
<s:Envelope xmlns:s=http://www.w3.org/2001/06/soap-envelope><s:Body>
<n:getQuoteResponse xmnls:n=“urn:QuoteService”><value xsi:type=“xsd:float”>
98.06</value>
</n:getQuoteResponse></s:Body>
</s:Envelope>
Web Services: SOAP 19
SOAP Faults
<s:Envelope xmlns:s=“http://www.w3.org/2001/06/soap-envelope” ><s:Body>
<s:Fault><faultcode>Client.Authentication</faultcode><faultstring>Invalid credentials</faultstring><faultactor>http://acme.com/</faultactor><details> <!-- application specific details></details>
</s:Fault></s:Body>
</s:Envelope>
Web Services: SOAP 20
Standard SOAP Fault Codes
Version Mismatch MustUnderstand: specify which header blocks
were not understood Server: error can’t be directly linked to the
processing of the message Client: there is a problem in the message (e.g.
invalid authentication credentials)
Web Services: SOAP 21
SOAP Data Encoding One possible method of serializing data and
encode them into XML Section 5 of the SOAP standard General rules
Web Services: SOAP 22
Compound Values
A compound value represents a combination of two or more accessors grouped as children of a single accessor
Each accessor has a different name (structs)
<name><firstname>Joe</firstname><lastname>Smith</lastname>
</name>
Web Services: SOAP 23
Arrays
An array is a compound value in which the accessors have the same name
<people><person name=‘joe smith’ /><person name=‘john doe’ />
</people>
Web Services: SOAP 24
Multi-Referenced Accessor
<people><person name=‘joe smith’>
<address href=‘#address-1’></person><person name=‘john doe’>
<address href=‘#address-1’></person>
</people><address id=‘address-1’>
<street>111 First Street</street><city>New York</city><state>New York</state>
</address>
Web Services: SOAP 25
Express the Data Type of an Accessor Use the xsi:type attribute on each accessor,
explicitly referencing the data type according to the XML Schema specification:<person><name xsi:type=“xsd:string”>John Doe</name>
Reference an XML Schema document that defines the exact data type of a particular element within its definition:
<person xmlns=“personschema.xsd”><name>John Doe</name></person>
Reference some other type of schema document that defines the data type of a particular element within its definition:<person xmlns=“urn:some_namespace”><name>John Doe</name>
Web Services: SOAP 26
SOAP Data Types Two alternate syntaxes for expressing instances
of data types Anonymous accessor:
<SOAP-ENC:int>36</SOAP-ENC:int> Anonymous because its name is its type rather
than a meaningful id for the value Named accessor:
<value xsi:type=“xsd:int”>36</value>
Web Services: SOAP 27
Arrays
Arrays
int a[3] = {1, 2, 3};
b = Add([in]a);
<m:Add xmlns:m=“http://a.com/Calculator” xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/”> <a SOAP-ENC:arrayType=“xsd:int[3]”> <SOAP-ENC:int>1</SOAP-ENC:int> <SOAP-ENC:int>2</SOAP-ENC:int> <SOAP-ENC:int>3</SOAP-ENC:int> </a></m:Add>
Web Services: SOAP 28
By value : Add([in] int a, [in] int b);
By reference : Square([in, out] int &a);
Values and References
<m:Add xmlns:m=“http://a.com/Calculator”><a xsi:type=“integer”>3</a><b xsi:type=“integer”>4</b>
</m:Add>
<m:Add xmlns:m=“http://a.com/Calculator”><a href=“#arg” />
</m:Add><a id=“arg” xsi:type=“integer”>8</a>
Web Services: SOAP 29
Summary
SOAP protocol: an XML encoding scheme to exchange information between web processes:Document style: XML documentsRPC style: packing parameters in XML format
Typically SOAP/HTTP, others are possible Low level in terms of process/service modeling