Management of XML and Semistructured Data

Download Report

Transcript Management of XML and Semistructured Data

Simple Object Access Protocol
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
2
Port vs Web Server
Internal
Service
External
Application
Internal
Service
External
Application
Web Services: SOAP
TCP
External
Application
Internal
Service
3
Port vs Web Server
External
Application
Internal
Service
TCP
External
Application
Web
Server
External
Application

Internal
Service
Internal
Service
“XML-RPC”
Port 80?
 SOAP is not restricted to port 80

Web Services: SOAP
4
SOAP over HTTP
 Request
example
POST /Temperature HTTP/1.1
Host: www.weather.com
Content-Type: text/xml
Content-Length: <whatever>
SOAPAction: “urn:StockQuote#GetQuote”
HTTP Header
Soap Extensions
<s:Envelope
xmlns:s=“http://www.w3.org/2001/06/soapenvelope">
<s:Body>
XML Payload
……
(SOAP request)
</s:Body>
</s:Envelope>
Web Services: SOAP
5
SOAP over HTTP

Response example
HTTP/1.1 200 OK
Content-Type: text/xml
Content-Length: <whatever>
HTTP Header
<s:Envelope
xmlns:s=“http://www.w3.org/2001/06/soapenvelope">
<s:Body>
……
</s:Body>
XML Payload
</s:Envelope>
(SOAP response)
Web Services: SOAP
6
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
7
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
8
SOAP Example: Error
<soap:Fault>
<faultcode>0x800700E</faultcode>
<faulstring>Unknown book</faultstring>
</soap:Fault>
Web Services: SOAP
9
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
10
SOAP Message with Binary Attachments

A SOAP message can also contain binary attachments
using MIME encoding
MIME Header
MIME Boundary
Root Body Part
SOAP Envelope
SOAP Header
(optional)
SOAP Body
“payload”
MIME Boundary
Body Part
Attachment
Web Services: SOAP
11
SOAP Structure
SOAP Envelope
SOAP Header
Header Block
...
Header Block
SOAP Body
Body Block
...
Body Block
Web Services: SOAP
 Envelope
contains
 Header
 Body
 Header
is optional
 Out-of-band information
such as…
 Authentication
information
 Message routes
 Logging
 Transaction flow
 Body contains XML body of
RPC call
12
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
13
XML Messaging in SOAP
 EDI:
Electronic Document Interchange
 SOAP with EDI: XML documents
“Document style SOAP”
 RPC:
distributed computing, web services
 “RPC-style” SOAP: parameters and return values
Web Services: SOAP
14
Purchase Order in Document-Style SOAP
<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>
Web Services: SOAP
15
RPC Messages
 Typically
two messages
Request Message
SOAP Client
SOAP Server
Response Message
Web Services: SOAP
16
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
17
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
18
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
19
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
20
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
21
Compound Values

A compound value represents a combination of two or
more accessors grouped as children of a single
accessor
<name>
<firstname>Joe</firstname>
<lastname>Smith</lastname>
</name>

Each accessor has a different name (structs)
Web Services: SOAP
22
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
23
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
24
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
25
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
26
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
27
Values and References

By value : Add([in] int a, [in] int b);
<m:Add xmlns:m=“http://a.com/Calculator”>
<a xsi:type=“integer”>3</a>
<b xsi:type=“integer”>4</b>
</m:Add>

By reference : Square([in, out] int &a);
<m:Add xmlns:m=“http://a.com/Calculator”>
<a href=“#arg” />
</m:Add>
<a id=“arg” xsi:type=“integer”>8</a>
Web Services: SOAP
28
Summary
 SOAP
protocol: an XML encoding scheme to exchange
information between web processes:
 Document style: XML documents
 RPC style: packing parameters in XML format
 Typically SOAP/HTTP, others are possible
 Low level in terms of process/service modeling
Web Services: SOAP
29