Title: 3'1 SOAP Introduction
13.1 SOAP Introduction
2What is SOAP?
- SOAP is an XML-based protocol for exchanging
information between computers - Mainly use for performing remote procedure calls
transported via HTTP - Different from CORBA, DCOM or Java RMI, SOAP
messages are entirely written in XML - Hence platform and language independent
- E.g. SOAP java client running on Linux can
connect to a Microsoft SOAP server running on
Windows XP - At the same time, a Perl client running on
Solaris can also connect to the same SOAP server
3What does SOAP Define?
- SOAP envelope specification
- Specify the rules for encapsulating data being
transferred between computers - In case of failure, define how to encode error
messages - Data encoding rules
- Define how the data are encoded
- E.g. the rule to encode floating point numbers
- Most conventions are based on the W3C XML Schema
- RPC conventions
- Define how a RPC can be proceeded
- E.g. how to specify the procedure name, pass
parameters and receive response (returned results)
4SOAP vs XML-RPC
- Similarities
- Use XML for messaging
- Messages are usually embedded into HTTP header
- Use request/response mechanism
- Mainly use in remote procedure call
- Platform independent
- Language independent
- Differences
- SOAP messages are more complicated than XML-RPC
- Make use of XML namespaces and XML Schemas
- Hence give a standard way for data encoding and
RPC - Thus allow automatic method invocation on the Web
5SOAP in Action
XML
HTTP
SOAP Request
SOAP client
SOAP server
SOAP Response
HTTP
XML
Hence SOAP messages can be delivered via the Web
6SOAP Communication Styles
- SOAP supports two different communication styles
- RPC Style
- Uses the SOAP RPC conventions, hence the
communication method and procedure are governed
by the conventions - Conceptually similar to other RPCs
- The default of early SOAP implementations
- Document Style
- Also known as message-oriented style
- Sending non-encoded XML content
- Require more programming work on server and
client sides to interpret the messages - More flexible communication and provides the best
interoperability
7A Sample Request in RPC Style
lt?xml version1.0 encodingUTF-8?gt ltSOAP-ENVE
nvelope xmlnsSOAP-ENVhttp//schemas.xmlsoap.or
g/soap/envelope/ xmlnsxsihttp//www.w3.org/20
01/XMLSchema-instance xmlnsxsdhttp//www.w3.o
rg/2001/XMLSchemagt ltSOAP-ENVBodygt
ltns1getTemp xmlnsns1urnxmethods-Temperatu
re SOAP-ENVencodingStyle
http//schemas.xmlsoap.org/soap/encoding/gt
ltzipcode xsitypexsdstringgt10016lt/zipcodegt
lt/ns1getTempgt lt/SOAP-ENVBodygt lt/SOAP-ENVEnve
lopegt
Try to call the remote method getTemp with input
parameter, a zipcode 10016
8A Sample Response in RPC Style
lt?xml version1.0 encodingUTF-8?gt ltSOAP-ENVE
nvelope xmlnsSOAP-ENVhttp//schemas.xmlsoap.or
g/soap/envelope/ xmlnsxsihttp//www.w3.org/20
01/XMLSchema-instance xmlnsxsdhttp//www.w3.o
rg/2001/XMLSchemagt ltSOAP-ENVBodygt
ltns1getTempResponse xmlnsns1urnxmethods-T
emperature SOAP-ENVencodingStyle
http//schemas.xmlsoap.org/soap/encoding/gt
ltreturn xsitypexsdfloatgt71.0lt/returngt
lt/ns1getTempResponsegt lt/SOAP-ENVBodygt lt/SOAP-E
NVEnvelopegt
Return a double 71.0 which represents the
temperature
9SOAP Messages
- In most cases, we do not need to directly
programming in SOAP - Dozens of SOAP implementations now freely exist
on the Internet - Apache SOAP (Axis)
- Microsoft SOAP ToolKit
- Allow generating SOAP messages automatically
using High Level Language, e.g. Java, C, Perl - Understanding of SOAP message structure enables
us to intercept a SOAP transaction and to debug a
SOAP application
10Message Structure
SOAP Message
Envelope (mandatory)
Header (optional)
Body (mandatory)
Fault (optional)
11lt?xml version1.0 encodingUTF-8?gt ltSOAP-ENVE
nvelope ltSOAP-ENVHeadergt
lt/SOAP-ENVHeadergt ltSOAP-ENVBodygt
ltSOAP-ENVFaultgt
lt/SOAP-ENVFaultgt
lt/SOAP-ENVBodygt lt/SOAP-ENVEnvelopegt
Example
Envelope Mandatory
Body Mandatory
Header Optional
Fault Optional
12SOAP message Envelope
- Every SOAP message has a root Envelope element
- Does not define the SOAP version
- Rather, use namespaces to differentiate versions
- For SOAP 1.2, the namespace URI is
- http//www.w3.org/2001/09/soap-envelope
Namespace for SOAP 1.1
ltSOAP-ENVEnvelope xmlnsSOAP-ENV
http//schemas.xmlsoap.org/soap/envelope/
lt/SOAP-ENVEnvelopegt
13XML Namespaces
- XML document can define its own markup language
or vocabularies - XML uses namespace to uniquely identify XML
vocabularies
Define the namespace of SOAP-ENV is
ltSOAP-ENVEnvelope xmlnsSOAP-ENV
http//schemas.xmlsoap.org/soap/envelope/
lt/SOAP-ENVEnvelopegt
Define also element Envelope is part of namespace
SOAP-ENV
Attribute for defining namespace
14- We do not need to really go to
- http//schemas.xmlsoap.org/soap/envelope/
- to do anything
- Since this URL is unique, the word SOAP-ENV is
also unique in this document - If there is another XML document that has the
same word SOAP-ENV but referring to different
URL, it means that SOAP-ENV is different from
this SOAP-ENV - In contrary, if they refer to the same URL, it
means that the two SOAP-ENV are referring to the
same thing
15ltSOAP-ENVEnvelope xmlnsSOAP-ENV
http//schemas.xmlsoap.org/soap/envelope/
xmlnsxsihttp//www.w3.org/2001/XMLSchema-instan
ce xmlnsxsdhttp//www.w3.org/2001/XMLSchemagt
lt/SOAP-ENVEnvelopegt
- Define the namespaces for data encoding
- Need to specify this to server to declare the
data in the document are encoded based on a
particular convention - Again, we do not need to really go to these Web
sites to do anything. Just to imply uniqueness
and for verification purpose
16lt?xml version1.0 encodingUTF-8?gt ltSOAP-ENVE
nvelope ltSOAP-ENVHeadergt
lt/SOAP-ENVHeadergt ltSOAP-ENVBodygt
ltSOAP-ENVFaultgt
lt/SOAP-ENVFaultgt
lt/SOAP-ENVBodygt lt/SOAP-ENVEnvelopegt
Header
- Optional. For specifying additional
application-level requirements - For example (1) specify a digital signature (2)
specify an account number
17lt?xml version1.0 encodingUTF-8?gt ltSOAP-ENVE
nvelope ltSOAP-ENVHeadergt
lt/SOAP-ENVHeadergt ltSOAP-ENVBodygt
ltSOAP-ENVFaultgt
lt/SOAP-ENVFaultgt
lt/SOAP-ENVBodygt lt/SOAP-ENVEnvelopegt
Body
- Mandatory to all SOAP messages
- Carry the actual content such as the RPC requests
or responses
18lt?xml version1.0 encodingUTF-8?gt ltSOAP-ENVE
nvelope ltSOAP-ENVHeadergt
lt/SOAP-ENVHeadergt ltSOAP-ENVBodygt
ltSOAP-ENVFaultgt
lt/SOAP-ENVFaultgt
lt/SOAP-ENVBodygt lt/SOAP-ENVEnvelopegt
Fault
- In case of error, the body element should contain
a fault sub-element - Indicate the error code and the possible cause of
error
19- May contain the following elements
20ltSOAP-ENVFaultgt ltfaultcode xsitype"xsdstring
"gt SOAP-ENVClientlt/faultcodegt
ltfaultstring xsitype"xsdstring"gt Failed
to locate method (ValidateCreditCard) in
class (examplesCreditCard) at
/usr/local/ActivePerl-5.6/lib/
site_perl/5.6.0/SOAP/Lite.pm line 1555.
lt/faultstringgt lt/SOAP-ENVFaultgt
21 22SOAP Data Encoding
- A data is just a sequence of 1 and 0
- To allow different computers understand the
meaning of a data (string, integer, float ), a
standard data type encoding method is required - The original XML 1.0 specification does not
include rules for encoding data type - Later W3C released the XML Schema and provided a
standard framework for encoding data type - SOAP specification adopted the XML Schema, with
exception such as arrays and structs
23Scalar Types
- A scalar type data contains exactly one value
- e.g. string, Boolean, float, double. int, date,
time, etc - SOAP adopts all the built-in simple types
specified by XML Schema - For details, see
- http//www.w3.org/TR/2000/WD-xmlschema-0-20000407
/
24Follow the SOAP 1.2 encoding method. For SOAP
1.1, use schemas.xmlsoap.org/soap/encoding/
ltSOAP-ENVBodygt ltns1getPriceResponse
xmlnsns1"urnexamplespriceservice
SOAP-ENVencodingStyle "http//www.w3.org/200
1/09/soap-encoding"gt ltreturn
xsitype"xsddouble"gt 54.99lt/returngt
lt/ns1getPriceResponsegt lt/SOAP-ENVBodygt
xsitype is set to xsddouble, means a double
number is to be returned
25Compound Types
- Compound type data contains multiple values
- Can be further divided into arrays and structs
- Arrays contain multiple values of the same type
- Some implementations support multidimensional
array - Structs contain multiple values, but each element
is specified by a name
26Arrays
- Need to specify both the element type and array
size
ltreturn xmlnsns2 http//www.w3.org/2001/09/
soap-encoding xsitypens2Array
ns2arrayTypexsddouble2gt ltitem
xsitype"xsddouble"gt54.99lt/itemgt ltitem
xsitype"xsddouble"gt19.99lt/itemgt lt/returngt
Specify the type is array and there are two
double numbers in the array
27Structs
- Struct contains multiple values, but each element
is specified with a unique accessor element
Accessor names
ltreturn xmlnsns2"urnexamples"
xsitype"ns2product"gt ltname
xsitype"xsdstring"gt Red Hat Linuxlt/namegt
ltprice xsitype"xsddouble"gt54.99lt/pricegt
ltdescription xsitype"xsdstring"gt Red Hat
Linux Operating System lt/descriptiongt ltSKU
xsitype"xsdstring"gtA358185lt/SKUgt lt/returngt
28Literal Encoding
- It is possible to ignore all the SOAP
specification and embed a generic XML document
directly into a SOAP message - Doing so is referred to as literal encoding
- Different implementation may have different ways
to encode literal XML document - For Apache SOAP, need to specify the namespace
- http//xml.apache.org/xml-soap/literalxml
29Specify the encoding style
SOAP-ENVencodingStyle "http//xml.apache.org/xml
-soap/literalxml"gt ltreturngt ltproduct
sku"A358185"gt ltnamegtRed Hat Linuxlt/namegt
ltdescriptiongtRed Hat Linux Operating
Systemlt/descriptiongt
ltpricegt54.99lt/pricegtlt/productgt lt/returngt
Doing the same as the struct example but without
the SOAP rules. Solely in generic XML format
30- The two communication styles (RPC, document) and
two encodings (encoded, literal) methods can be
freely intermixed - RPC / encoded
- Following SOAP RPC convention for messaging and
also following SOAP data encoding method - Most straightforward to implement but also most
restrictive - Can introduce interoperability problem
- Most popularly used in early version of SOAP
implementation (WebSphere 4 and 5.0) - RPC / literal
- Following SOAP RPC convention for messaging but
sending literal XML data - Less restrictive
31- Document / literal
- Sending non-encoded XML message with literal XML
data - Need more programming work for the server and
client to interpret the data - Provide the best interoperability between Java
and non-Java implementations - Default for recently implementation of SOAP
(WebSphere 5.1 and Microsoft Toolkit 3.0) - Document / encoded
- Not used in practice
32SOAP Interoperability
- Although SOAP was developed to solve the
interoperability problem when doing RPC, it also
has interoperability problem - For example, there is known problem between
Apache SOAP, SOAPLite for Perl and the
Microsoft SOAP Toolkit - Apache SOAP requires all parameters to be typed
via the xsitype attribute, while others dont - Microsoft SOAP Toolkit supports multidimensional
array while others dont - Much effort has been made, but still some way to
go to totally solve the problem
33Web Services Interoperability (WS-I)
- WS-I is an organization chartered to promote Web
service interoperability across platforms, OS and
programming languages (see http//www.ws-i.org/) - Establish WS-I Basic Profile which outlines the
requirements to which WSDL and Web service
protocol (SOAP/HTTP) traffic must comply - Provide WS-I validation tools currently support
WS-I Basic Profile 1.0 - One of the important suggestions made is the
banning of RPC / encoded style - However, the use of RPC / encoded style provides
much convenience in exposing preexisting classes
and methods - Much work is being performed to make sure the RPC
style works between most SOAP implementations