Title: Ace104 Lecture 5
1Ace104Lecture 5
- The Flavor of SOAP A study of the key concepts
without all of the detail
2Some facts about SOAP
- SOAP no longer stands for Simple Object Access
Protocol - This was dropped in 2003 with publication of v1.2
- Considered to be a misleading name
- Originally was XML-RPC
- Created in 1998 as a very lightweight protocol
for rpc - Was basis for development of SOAP several years
later - SOAP currently maintained by W3C XML working
group - SOAP and XML-RPC are based entirely on XML
3SOAP as a messaging protocol
- SOAP is fundamentally a stateless, one-way
message exchange paradigm - However, applications can create more complex
interaction patterns (e.g., request/response,
request/multiple responses, etc.) by combining
such one-way exchanges with features provided by
an underlying protocol and/or application-specific
information. - SOAP is silent on the semantics of any
application-specific data it conveys, as it is on
issues such as the routing of SOAP messages,
reliable data transfer, firewall traversal, etc. - However, SOAP provides the framework by which
application-specific information may be conveyed
in an extensible manner. Also, SOAP provides a
full description of the required actions taken by
a SOAP node on receiving a SOAP message.
4SOAP
- SOAP is made up of three major parts
- A generic XML messaging framework
- An data encoding standard
- An RPC (remote procedure call) framework
- It is possible to use just the messaging
framework or messaging framework/encoding
standard without using the RPC mechanism (though
latter is where much of power/usefulness lies).
5Web Services
- Note that classic Web Services are made up of
three parts - SOAP
- WSDL (Web Services Descriptor Language)
- UDDI (Universal Description, Discovery, and
Integration) - All three are based on XML
- SOAP simply defines the structure of the XML
document used to transfer the message - WSDL and UDDI are covered next
6SOAP Messaging framework
- Just defines a generic message XML schema
- Virtually any type of message you can think of
can be packaged as a SOAP message. - However, doing so without RPC mechanisms takes
only very small advantage of the features defined
in the SOAP standard
7General (Basic) Structure SOAP Message
SOAP Envelope
- Envelope
- Defines the content of the message
- Header (optional)
- Contains destination information, versioning,
extensions - Good place for security
- Body
- Contains payload
SOAP Header
SOAP Body
Payload Document(s)
SOAP Fault
8General (Basic) Structure SOAP Message
- ltsoapEnvelope
- xmlnssoap"http//schemas.xmlsoap.org/soap/encodi
ng/" - soapencodingStyle"http//schemas.xmlsoap.org/soa
p/encoding/"gt - ltsoapHeadergt
- ... ...
- lt/soapHeadergt
- ltsoapBodygt
- lt!-- User request code here --gt
- ltsoapFaultgt
- ... ...
- lt/soapFaultgt
- lt/soapBodygt
- lt/soapEnvelopegt
9SOAP encoding
- In order to build SOAP messages from our language
of choice, we need to know how to serialize data
-- ie the rules for representing an integer,
string, or floating point number. The
serialization of data inside a SOAP message is
referred to as encoding - The encodingStyle attribute defined by the SOAP
specification is used to identify the encoding
rules used in a particular message. - SOAP does this in a language agnostic way, much
like CORBA (but not in binary form) - If the encodingStyle attribute does not appear in
the message, the receiver cannot make any
assumptions about how data will be represented
within the message
10SOAP Encoding
- You may be wondering about the relationship
between encoding and XML Schemas - Encoding can make use of XML Schemas.
- The SOAP Specification defines a single set of
(recommended) encoding rules call SOAP encoding.
SOAP encoding is based on XML Schemas and as such
it closely models many of the standard types and
constructs. The value is http//schemas.xmlsoap.or
g/soap/encoding/, which points to the XML Schema
that defines the encoding rules. - SOAP encoding rules use XML Schemas heavily,
relying on the XML Schema datatypes namespace and
the type attribute. - The key difference is that encoding does not
mandate XML Schemas. - Encoding rules are simply identified by a URI.
The rules implied by that URI could be backed up
by nothing more than a verbal agreement, or
possibly some written documentation. - This allows developers who do not necessarily
need the capabilities of XML Schemas to forego
their use and start sending messages with
encoding rules based on an accepted URI.
11SOAP Encoding
- For example, SOAP stipulates that an array of
three integers be represented as - ltSOAP-ENCArray SOAP-ENCarrayType"xsdint3"gtlt
SOAP-ENCintgt8lt/SOAP-ENCintgtltSOAP-ENCintgt5lt/SOA
P-ENCintgtltSOAP-ENCintgt9lt/SOAP-ENCintgt - lt/SOAP-ENCArraygt
- SOAP also provides a type for representing binary
data - One approach for working with binary data is to
use the base64 type. We can represent binary
data, such as an image file, as an array of bytes
in the message. - The base64 type converts binary data to text
using the base64-encoding algorithm of XML
Schemas. There is no relationship between SOAP
and base64-encoding - If we use it, our application (or implementation
of SOAP for your platform) must be able to
understand and work with base64-encoding.
12SOAP RPC
- The third part of SOAP is an RPC mechanism that
turns messages into method calls - We have a generic message structure data. It
requires just a little more work to turn the
message into a function call. - Must be a standard way to represent parameters
and return values, exceptions, etc. - Note that the encoding and rpc mechanisms are
only important if - SOAP is being automatically generated/read
from the application level - (see next slide) in a general way
13SOAP RPC cartoon
VB application
Java application
InvoiceVB-Structure
InvoiceJava-Structure
SOAP client
SOAP Server
SOAP Message
The client application thinks its making a
procedure call to a remote module
14Sample RPC rules
- This is intended just to give you a flavor. Best
to allow - applications to do this automatically
- Consider the following three method signatures
- // Reverse the string, s, and return the new
string.? - string ReverseString ( in string s )
- // Reverse the string, s, and return the new
string.? - void ReverseString ( in string s, out string
sRev ) - // Reverse the string, s, passed in by reference.
- ?void ReverseString ( in, out string s )
- See next slide for SOAP rpc encoding
15Sample rpc rules
The first version reverses the string and returns
the result as the return value of the
method ltxReverseStringResponse
xmlnsx"http//www.wrox.com/"gt ltxret
xsitype"xsdstring"gtTHORlt/xretgt lt/xReverseStri
nggt The second version has no return value, but
instead uses an out parameter called
sRev ltxReverseStringResponse
xmlnsx"http//www.wrox.com/"gt ltxsRev
xsitype"xsdstring"gtTHORlt/xsRevgt lt/xReverseStr
inggt The final version reverses the string after
passing it by reference, so the parameter s is
both an in and out parameter ltxReverseStringRes
ponse xmlnsx"http//www.wrox.com/"gt ltxs
xsitype"xsdstring"gtTHORlt/xsgt lt/xReverseString
gt
16SOAP transport
- Recall that SOAP is just a generic message
envelope - Augmented by encodingstyle and simple rpc rules,
it becomes a powerful middleware layer for remote
procedure calls, if one chooses to use it that
way - Now we must consider how to transport SOAP
messages -- this is the final ingredient in
making it something useful
17SOAP protocol bindings
- Questionhow are SOAP messages transmitted?
- Answer using existing protocols (http, SMTP,
etc.) - This has some obvious advantages vs. defining its
own protocol - Piggybacks on security model, general robustness
- This has some disadvantages also
- What are these?
- SOAP defines bindings to different protocols that
specify how SOAP is used with that protocol to
send messages. - http is most popular
18Inside http
- http is a simple, flexible protocol
- Some examples
- GET http//people.cs.uchicago.edu/asiegel/lottery
/lotto.html - POST /path/script.cgi HTTP/1.0
- From frog_at_jmarshall.com
- User-Agent HTTPTool/1.0
- Content-Type application/x-www-form-urlencoded
- Content-Length 32
- homeCosbyfavoriteflavorflies
- POST /path/script.cgi HTTP/1.0
- From frog_at_jmarshall.com
- User-Agent HTTPTool/1.0
- Content-Type text/xml
- Content-Length 32
- ltgreetinggthello worldlt/greetinggt
19Testing http
- Good idea to play around with http by connecting
to server and issuing http commands - There are a two typical ways to do this
- Using telnet, which allows arbitrary commands to
be passed to a server - telnet people.cs.uchicago.edu 80
- Note that expect can be useful in automating this
- Using a socket library in a programming language
(see sock.py on website) - Question how does the server obtain the uploaded
data in each case?
20Role of SOAP
- Note that the http XML is the important thing
here - SOAP only helps standardize the meaning of the
messages that are sent - In terms of datatypes for rpc
- In terms of headers, faults, etc.
- Note that it is still possible to bypass SOAP and
define your own xml-based protocol, retaining
many of the advantages of SOAP.
21Sorting out the APIs
- In Java the following directly related APIs are
available - SAAJ
- SOAP with Attachments API for Java
- Provides a relatively low-level interface that
allows one to programmatically construct/decompose
SOAP messages and send to web server - Intended more tool writers. Good for learning.
- JAX-RPC
- Java API form XML-based RPC
- Javas rmi framework over SOAP
- Compare RMI, CORBA, etc.
- Makes developer unaware of SOAP internals
- Apache XML-RPC for Java
- A framework for remote procedure calls using
XML-RPC - Recall that XML-RPC is an alternative protocol to
SOAP
22Looking deeper into SOAP
23Envelope
- MUST be the root element of the SOAP message
- MUST be associated with SOAP envelope namespace
- http//schemas.xmlsoap.org/soap/envelope
- http//www.w3.org/2001/06/soap-envelope in SOAP
1.2 (Oct 15, 2002) - SOAP serialization namespace
- Encoding Style attributes can contain a URI
describing how the data should be serialized. - Two usual styles (more on this later)
- "SOAP Section 5" encoding http//www.w3.org/2001/
06/soap-encoding - Literal encoding (no namespace used or set to
empty string) - SOAP message MUST NOT contain
- DTD
- Processing Instructions.
24Envelope versioning
- Version determined by the namespace associated
with the Envelope element - SOAP 1.1 Envelope version http//schemas.xmlsoap
.org/soap/envelope - If any other namespace used, assume it's a
version problem - Versioning problems must generate a SOAP Fault
- Example SOAP fault
- HTTP/1.0 500 Internal Server Error
- Content-Type text/html charset"utf-8"
- Content-length 311
- ltenvEnvelope xmlnsenv"http//schemas.xmlsoap.or
g/soap/envelope/"gt - ltenvBodygt
- ltenvFaultgt
- ltfaultcodegtenvVersionMismatchlt/faultcodegt
- ltfaultstringgtSOAP Envelope Version
Mismatchlt/faultstringgt - lt/envFaultgt
- lt/envBodygt
- lt/envEnvelopegt
25Envelope Versioning Fault in SOAP 1.2
- SOAP 1.2 (Oct 15, 2002) has defined an Upgrade
element in the header for the versioning fault - lt?xml version"1.0" ?gt
- ltenvEnvelope xmlnsenv"http//schemas.xmlsoap.or
g/soap/envelope/"gt - ltenvHeadergt
- ltupgUpgrade xmlnsupg"http//www.w3.org/2002
/06/soap-upgrade" - gt
- ltenvelope qname"ns1Envelope" xmlnsns1"http//w
ww.w3.org/2002/06/soap-envelope" - /gt
- lt/upgUpgradegt
- lt/envHeadergt
- ltenvBodygt
- ltenvFaultgt
- ltfaultcodegtenvVersionMismatchlt/faultcodegt
- ltfaultstringgtVersion Mismatchlt/faultstringgt
- lt/envFaultgt
- lt/envBodygt
- lt/envEnvelopegt
26Header
- Optional
- If present, must immediately follow the SOAP
Envelope XML element followed by any header
entries - Uses same namespace as Envelope
- Often contains meta-information regarding the
method call. - Examples
- Security
- No security mechanisms yet, but soon
- Transaction IDs
27Header
- actor attribute ? defines the URI for which
the header elements are intended (i.e. who should
process a Header element) - mustUnderstand attribute ? how to process
(default is 0 if not present) - encodingStyle attribute ? used to describe how
data (such as binary integers) are marshaled into
characters in the XML document - ltenvHeadergt
- lttTransactionID xmlnst"http//www.cs.uchicago.
edu/dangulo/transact" envmustUnderstand"1"
envactor"http//www.cs.uchicago.edu/dangulo/tran
sact" - gt
- 42
- lt/tTransactionIDgt
- ltmlocalizations
- xmlnsm"http//www.cs.uchicago.edu/dangulo/lo
calize/" - envactor"http//www.cs.uchicago.edu/dangulo/
currency" - gt
- ltmlanguagegtenlt/mlanguagegt
- ltmcurrencygtUSDlt/mcurrencygt
- lt/mlocalizationsgt
- lt/envHeadergt
28actor Attribute
- The SOAP message often gets passed through
several intermediaries before being processed - For example, a SOAP proxy service might get the
message before the target SOAP service - Header may contain information for both
- intermediary service
- target service
- actor attribute specifies which service should
process a specific Header element - actor attribute is replaced by role attribute in
SOAP 1.2
29Intermediary Services
- SOAP requires that an intermediary strip off
Header elements specified for that intermediary
before passing the message to the next service in
the chain. - If information in a Header element targeted for
an intermediary is also needed by another service
in the chain - The intermediary service may insert additional
Header elements with an actor attribute that
specifies the downstream service - In fact, any service may insert any Header
elements that it deems necessary - If a Header element has no actor attribute
- It is assumed to be destined for the final
recipient - This is equivalent to adding an actor attribute
with the URL of the final recipient
30mustUnderstand Attribute
- Also put on a Header element
- If its value is "1"
- recipient is required to understand and make
proper use of the information supplied by that
element - intended for situations where recipient can't do
its job unless it knows what to do with the
specific information supplied by this particular
element - Examples of use
- Client is upgraded to a new version which
includes extra information - username
- security
31mustUnderstand Attribute
- If the recipient does not understand this element
- Must respond with a SOAP Fault
- HTTP/1.0 500 Internal Server Error
- Content-Type text/xml charst"utf-8"
- Content-length 287
- ltenvEnvelope xmlnsenv"http//schemas.xmlsoap.or
g/soap/envelope/"gt - ltenvBodygt
- ltenvFaultgt
- ltfaultcodegtenvMustUnderstandlt/faultcodegt
- ltfaultstringgtSOAP Must Understand
Errorlt/faultcodegt - ltfaultactorgthttp//www.cs.uchicago.edu/dangulo/tra
nsactlt/faultactorgt - lt/envFaultgt
- lt/envBodygt
- lt/envEnvelopegt
- faultactor indicates where fault took place
- We'll look at Faults in more detail later
- Attribute values change to "true" / "false" in
SOAP 1.2
32Some examples
33Sample SOAP message for travel reservation
lt?xml version'1.0' ?gt ltenvEnvelope
xmlnsenv"http//www.w3.org/2003/05/soap-envelope
"gt ltenvHeadergt ltmreservation
xmlnsm"http//travelcompany.example.org/reservat
ion" envrole"http//www.w3.org/2003/05
/soap-envelope/role/next"
envmustUnderstand"true"gt ltmreferencegtuuid09
3a2da1-q345-739r-ba5d-pqff98fe8j7dlt/mreferencegt
ltmdateAndTimegt2001-11-29T132000.000-0500lt/m
dateAndTimegt lt/mreservationgt ltnpassenger
xmlnsn"http//mycompany.example.com/employees"
envrole"http//www.w3.org/2003/05/soap-
envelope/role/next" envmustUnderstand
"true"gt ltnnamegtAndrew Siegellt/nnamegt
lt/npassengergt lt/envHeadergt Next slide ..
34ltenvBodygt ltpitinerary xmlnsp"http//trav
elcompany.example.org/reservation/travel"gt
ltpdeparturegt ltpdepartinggtNew
Yorklt/pdepartinggt ltparrivinggtLos
Angeleslt/parrivinggt ltpdepartureDategt2001-12
-14lt/pdepartureDategt ltpdepartureTimegtlate
afternoonlt/pdepartureTimegt
ltpseatPreferencegtaislelt/pseatPreferencegt
lt/pdeparturegt ltpreturngt
ltpdepartinggtLos Angeleslt/pdepartinggt
ltparrivinggtNew Yorklt/parrivinggt
ltpdepartureDategt2001-12-20lt/pdepartureDategt
ltpdepartureTimegtmid-morninglt/pdepartureTimegt
ltpseatPreference/gt lt/preturngt
lt/pitinerarygt ltqlodging xmlnsq"http//tra
velcompany.example.org/reservation/hotels"gt
ltqpreferencegtnonelt/qpreferencegt lt/qlodginggt
lt/envBodygt lt/envEnvelopegt
35Sample SOAP reply
lt?xml version'1.0' ?gt ltenvEnvelope
xmlnsenv"http//www.w3.org/2003/05/soap-envelope
"gt ltenvHeadergt ltmreservation
xmlnsm"http//travelcompany.example.org/reservat
ion" envrole"http//www.w3.org/2003/05/soa
p-envelope/role/next"
envmustUnderstand"true"gt ltmreferencegtuuid09
3a2da1-q345-739r-ba5d-pqff98fe8j7dlt/mreferencegt
ltmdateAndTimegt2001-11-29T133500.000-0500lt/m
dateAndTimegt lt/mreservationgt ltnpassenger
xmlnsn"http//mycompany.example.com/employees"
envrole"http//www.w3.org/2003/05/soap-enve
lope/role/next" envmustUnderstand"tru
e"gt ltnnamegtAndrew Siegellt/nnamegt
lt/npassengergt lt/envHeadergt Next slide
36ltenvBodygt ltpitineraryClarification
xmlnsp"http//travelcompany.example.org/reservat
ion/travel"gt ltpdeparturegt ltpdepartinggt
ltpairportChoicesgt JFK LGA EWR
lt/pairportChoicesgt lt/pdepartinggt
lt/pdeparturegt ltpreturngt ltparrivinggt
ltpairportChoicesgt JFK LGA EWR
lt/pairportChoicesgt lt/parrivinggt
lt/preturngt lt/pitineraryClarificationgt
lt/envBodygt lt/envEnvelopegt
37Reply continuing conversational exchange
lt?xml version'1.0' ?gt ltenvEnvelope
xmlnsenv"http//www.w3.org/2003/05/soap-envelope
"gt ltenvHeadergt ltmreservation
xmlnsm"http//travelcompany.example.org/reservat
ion" envrole"http//www.w3.org/2003/05/soa
p-envelope/role/next"
envmustUnderstand"true"gt ltmreferencegtuuid0
93a2da1-q345-739r-ba5d-pqff98fe8j7dlt/mreferencegt
ltmdateAndTimegt2001-11-29T133650.000-0500lt/
mdateAndTimegt lt/mreservationgt ltnpassenger
xmlnsn"http//mycompany.example.com/employees"
envrole"http//www.w3.org/2003/05/soap-enve
lope/role/next" envmustUnderstand"tru
e"gt ltnnamegtAndrew Siegellt/nnamegt
lt/npassengergt lt/envHeadergt ltenvBodygt
ltpitinerary xmlnsp"http//travelcompany.exam
ple.org/reservation/travel"gt ltpdeparturegt
ltpdepartinggtLGAlt/pdepartinggt
lt/pdeparturegt ltpreturngt
ltparrivinggtEWRlt/parrivinggt lt/preturngt
lt/pitinerarygt lt/envBodygt lt/envEnvelopegt
38RPC
- Notice that previous did not include rpc
capability - To invoke a SOAP RPC, the following information
is needed - The address of the target SOAP node.
- The procedure or method name.
- The identities and values of any arguments to be
passed to the procedure or - method together with any output parameters and
return value. - 4. A clear separation of the arguments used to
identify the Web resource which - is the actual target for the RPC, as contrasted
with those that convey data or - control information used for processing the call
by the target resource. - The message exchange pattern which will be
employed to convey the RPC, - together with an identification of the so-called
"Web Method (on which more later) - to be used.
- 6. Optionally, data which may be carried as a
part of SOAP header blocks.
39SOAP RPC request with a mandatory header and two
input (or "in") parameters
lt?xml version'1.0' ?gt ltenvEnvelope
xmlnsenv"http//www.w3.org/2003/05/soap-envelope
" gt ltenvHeadergt ltttransaction
xmlnst"http//thirdparty.example.org/transaction
" envencodingStyle"http//example.com
/encoding" envmustUnderstand"true"
gt5lt/ttransactiongt lt/envHeadergt ltenvBodygt
ltmchargeReservation envencodingStyle"http
//www.w3.org/2003/05/soap-encoding"
xmlnsm"http//travelcompany.example.org/"gt
ltmreservation xmlnsm"http//travelcompany.examp
le.org/reservation"gt ltmcodegtFT35ZBQlt/mcodegt
lt/mreservationgt ltocreditCard
xmlnso"http//mycompany.example.com/financial"gt
ltnname xmlnsn"http//mycompany.example.com/
employees"gtAndrew Siegellt/nnamegt
ltonumbergt123456789099999lt/onumbergt
ltoexpirationgt2005-02lt/oexpirationgt
lt/ocreditCardgt lt/mchargeReservationgt
lt/envBodygt lt/envEnvelopegt
40RPC response with two output (or "out")
parameters
?xml version'1.0' ?gt ltenvEnvelope
xmlnsenv"http//www.w3.org/2003/05/soap-envelope
" gt ltenvHeadergt ltttransaction
xmlnst"http//thirdparty.example.org/transaction
" envencodingStyle"http//example.com/
encoding" envmustUnderstand"true"gt5lt/
ttransactiongt lt/envHeadergt ltenvBodygt
ltmchargeReservationResponse
envencodingStyle"http//www.w3.org/2003/05/soap-
encoding" xmlnsm"http//travelcompa
ny.example.org/"gt ltmcodegtFT35ZBQlt/mcodegt
ltmviewAtgt http//travelcompany.ex
ample.org/reservations?codeFT35ZBQ
lt/mviewAtgt lt/mchargeReservationResponsegt
lt/envBodygt lt/envEnvelopegt
41RPC response with a "return" value and two "out"
parameters
lt?xml version'1.0' ?gt ltenvEnvelope
xmlnsenv"http//www.w3.org/2003/05/soap-envelope
" gt ltenvHeadergt ltttransaction
xmlnst"http//thirdparty.example.org/transaction
" envencodingStyle"http//example.com/e
ncoding" envmustUnderstand"true"gt5lt/t
transactiongt lt/envHeadergt ltenvBodygt
ltmchargeReservationResponse
envencodingStyle"http//www.w3.org/2003/05/soap-
encoding" xmlnsrpc"http//www.w3.org/
2003/05/soap-rpc" xmlnsm"http//tra
velcompany.example.org/"gt
ltrpcresultgtmstatuslt/rpcresultgt
ltmstatusgtconfirmedlt/mstatusgt
ltmcodegtFT35ZBQlt/mcodegt ltmviewAtgt
http//travelcompany.example.org/reservations?cod
eFT35ZBQ lt/mviewAtgt
lt/mchargeReservationResponsegt
lt/envBodygt lt/envEnvelopegt
42Extra Slides
- In progress, read to get a sense of underlying
details
43Marshalling / Serialization
- To be interoperable, we use XML
- XML is ASCII, not binary
- End points use binary
- Must Marshall (Serialize) and UnMarshall
(DeSerialize) on the ends
44Body
- Message to exchange.
- Most often for RPC calls and error reporting.
- Immediate child element of SOAP Envelope XML
element - follows Header, if present
- Uses same namespace as Envelope and Header
- Contains serialized method arguments.
- Remote method name
- Used to name the method calls XML element
- Must immediately follow the SOAP body opening XML
tag. - SOAP Fault goes in the Body (of a response) too
- The only Body elements actually defined in the
SOAP specification are the SOAP Fault elements - Other elements are user defined
45Example
- A simple SOAP XML document requesting the price
of soap (leaving off the required namespaces
declarations) - ltenvEnvelopegt
- ltenvBodygt
- ltmGetPricegt
- ltItemgtLever2000lt/Itemgtlt/mGetPricegt
- lt/envBodygt
- lt/envEnvelopegt
- Note that namespaces qualifiers are not required
on elements in the Body.
46Client/Server
- In order for SOAP to work
- Client must have code running that is responsible
for building the SOAP request. - Server must also be responsible for
- Understanding the SOAP request
- Invoking the specified method
- Building the response message
- Returning it to the client.
- These details are up to you.
- There already exist SOAP implementations for
languages such as C, Perl, VB, and Java.
47Binding
- SOAP is transport independent
- SOAP usually transported over HTTP
- SOAP can be transported over any protocol
- e.g. SMTP (e-mail)
- GSI (Globus Secure Transport)
- HTTPS
- pure sockets
- HTTP is the default binding
48SOAPAction HTTP header
- When using SOAP over HTTP, must include
SOAPAction header - SOAPAction HTTP request header field indicates
that it is a SOAP HTTP request (contains a SOAP
message) - The value
- Indicates the intent of the request in a manner
readily accessible to the HTTP server. - Is a URI
- Is up to the application not specified by SOAP
specs - Doesn't have to be resolvable
- An HTTP client must use SOAPAction header field
when issuing a SOAP HTTP Request. - An HTTP server must not process an HTTP request
as a SOAP HTTP request if it does not contain a
SOAPAction header field. - It may be used by firewalls to filter request
messages - It may be used by servers to facilitate
dispatching of SOAP messages to internal message
handlers - It should not be used as an insecure form of
access authorization.
49SOAPAction HTTP header
- Example
- POST /xt/services/ColorRequest HTTP/1.0
- Content Length 442
- Host localhost
- Content-type text/xml charsetutf-8
- SOAPAction "/getColor"
- lt!?xml version"1.0" encoding"UFT.8"?gt
- ltenvEnvelope
- envencodingStyle"http//schemas.xmlsoap.org/SO
AP/encoding/" - xmlnsxsd"http//www.w3.org/2001/XMLSchema"
- xmlnsenv"http//schemas.xmlsoap.org/SOAP/envel
ope/" - xmlnsxsi"http//www.w3.org/2001/XMLSchema-inst
ance"gt - ...
50SOAP Messages with Attachments
- SOAP messages often have attachments, such as
pictures - The attachments don't have to be XML encoded, but
may be binary - The SOAP message becomes the root of a
Multipart/Related MIME structure - The SOAP message refers to the attachment using
a URI with the cid protocol - cid "content ID"
51SOAP Messages with Attachments
- MIME-version 1.0
- Content-Type Multipart/Related ...
- --MIME_boundary
- Content-Type text/xml ...
- lt?xml version"1.0" ?gt
- ltenvEnvelope ...
- ltsomeTag href"cidattached.gif_at_company.com"/gt
- ...
- lt/endEnvelopegt
- --MIME_boundary
- Content-Type image/gif
- Content-Transfer-Encoding binary
- Content-ID lt"attached.gif_at_company.com"gt
- ... binary gif image ...
52Encoding
- One type of encoding specified in "section 5" of
the SOAP spec - No default encoding (not even "section 5"
encoding) - Encoding rules exist to define mapping between
abstract data types and XML syntax (binary to
character mapping) - Encoding style is specified with the
encodingStyle attribute
53Encoding
- The encodingStyle attribute can be placed on any
element allowing mixed encoding styles - Two values most often used (anything possible)
- "SOAP Section 5" encoding http//www.w3.org/2001/
06/soap-encoding - Literal encoding (no namespace used or set to
empty string) - Also can do base64 encoding
- Can turn it off currently scoped style using an
empty string as URL ("") - parent scoped style becomes default again
54Response
- No Special HTTP Response headers (doesn't use
SOAPAction header) - Only special SOAP element is the Fault element
and its children - Otherwise, looks like a normal SOAP message
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltsoapEnvelope
- xmlnssoap"http//schemas.xmlsoap.org/soap/env
elope/" - soapencodingStyle"http//schemas.xmlsoap.org/
soap/encoding/" - xmlnsxsi"http//www.w3.org/1999/XMLSchema-ins
tance" - xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt
- ltsoapBodygt ltmFavoriteColorResponseMsg
- xmlnsm"http//www.cs.uchicago.edu
/dangulo/soap-methods"gt - ltanswer xsitype"xsdstring"gtRed
...No, Blue...Aarrgh!lt/answer gt - lt/mFavoriteColorResponseMsggt
- lt/soapBodygt
- lt/soapEnvelopegt
55Fault
- The ltfaultgt element is in the body of the SOAP
message - 0 or 1 ltfaultgt elements may be in the message
- The following subelements may be in the ltfaultgt
element
ltfaultcodegt One of the following codes (note the codes are strings)
ltfaultstringgt The error as a string
ltfaultactorgt Who reported the error
ltdetailgt Details of the problem
VersionMismatch The SOAP namespace is incorrect
MustUnderstand The client sent a header element with a MustUnderstand set to 1, and the server did not understand it
Client The message was incorrectly formed
Server The server had a problem
56Fault Code (faultcode)
- One of Two required elements in Fault element
- Other required element is faultstring
- Must be associated with SOAP envelope namespace
- Server error code could be something like a
back-end database couldn't be reached - Might try resending without modification
- Fault codes are extensible using "dot" notation
- Server.BridgeKeeperAbsent
- Server.BridgeKeeperAbsent.ThrownInGorge
57HTTP Headers with Faults
- Response code can only be 2xx or 500
- If message is received and understood, the
response should use 2xx
58HTTP Headers with Faults
- If message cannot be processed for any reason
- server does not understand the message
- message is improperly formatted
- message is missing information
- message cannot be processed for any other reason
- Response should be "500 Internal Server Error"
- 500 response should be followed by a SOAP
envelope which includes its own fault code - Reasoning the error is internal to the server as
far as HTTP is concerned
59Example Fault with HTTP and SOAP
- HTTP/1.0 500 Internal Server Error
- Content-Type text/xml charst"utf-8"
- Content-length 287
- ltenvEnvelope xmlnsenv"http//schemas.xmlsoap.or
g/soap/envelope/"gt - ltenvBodygt
- ltenvFaultgt
- ltfaultcodegtenvMustUnderstandlt/faultcodegt
- ltfaultstringgtSOAP Must Understand
Errorlt/faultcodegt - ltfaultactorgthttp//www.cs.uchicago.edu/dangulo/tra
nsactlt/faultactorgt - lt/envFaultgt
- lt/envBodygt
- lt/envEnvelopegt
60Bridge of Death Example
- Request
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltsoapEnvelope
- xmlnssoap"http//schemas.xmlsoap.org/soap/en
velope/" - soapencodingStyle"http//schemas.xmlsoap.org
/soap/encoding/" - xmlnsxsi"http//www.w3.org/1999/XMLSchema-in
stance" - xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt
- ltsoapBodygt
- ltmFavoriteColorRequestMsg
- xmlnsm"http//www.cs.uchicago.edu/dang
ulo/soap-methods/"gt - ltquestion xsitype"xsdstring"gt
- What is your favorite color?
- lt/question gt
- lt/mFavoriteColorRequestMsggt
- lt/soapBodygt
- lt/soapEnvelopegt
61Bridge of Death Response Example
- Response
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltsoapEnvelope
- xmlnssoap"http//schemas.xmlsoap.org/soap/env
elope/" - soapencodingStyle"http//schemas.xmlsoap.org/
soap/encoding/" - xmlnsxsi"http//www.w3.org/1999/XMLSchema-ins
tance" - xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt
- ltsoapBodygt ltmFavoriteColorResponseMsg
- xmlnsm"http//www.cs.uchicago.edu
/dangulo/soap-methods"gt - ltanswer xsitype"xsdstring"gtRed
...No, Blue...Aarrgh!lt/answer gt - lt/mFavoriteColorResponseMsggt
- lt/soapBodygt
- lt/soapEnvelopegt
62Data Encoding
- When sending data over a network
- Data must comply with the underlying transmission
protocol - Data must be formatted in such a way that both
the sending and receiving entities understand its
meaning - Even if endpoints are different platforms or
languages - Model for SOAP encoding is based on XML data
encoding - Encoding style given in Section 5 of the SOAP
specification used to be most common encoding
style used - Commonly called "SOAP-Section-5 encoding"
- namespace http//schemas.xmlsoap.org/encoding/
- Commonly aliased as SOAP-ENC
63Data Encoding and Schemas
- In SOAP, Schemas are used as references to
definitions of data elements - Aren't used to validate SOAP message data in
standard SOAP processing - However, there's nothing stopping you from doing
that - References to Schemas are often used as
namespaces in order to disambiguate a serialized
data element
64Data Encoding and Schemas
- SOAP Section 5 uses all of the build-in data
types defined in the "XML Schema Part 2
Datatypes" specification (at w3c.org) - These data types need to be disambiguated
- namespace http//www.w3.org/2001/XMLSchema
- Commonly aliased as xsd
- used with the data type names
- e.g. xsdstring
- A datum is given a data type using the type
attribute - This attribute must also be disambiguated
- namespace http//www.w3.org/2001/XMLSchema-instan
ce - Commonly aliased as xsi
- e.g. ltdialog xsitype"xsdstring"gtWhat is your
favorite color?lt/dialoggt
65Other Common Namespaces
- Envelope
- namespace http//schemas.xmlsoap.org/soap/envelop
e/ - Common aliases env or SOAP-ENV or SOAP or soap
- Example (we've seen this before)
- lt!?xml version"1.0" encoding"UFT.8"?gt
- ltSOAP-ENVEnvelope
- SOAP-ENVencodingStyle"http//schemas.xmlsoap.o
rg/SOAP/encoding/" - xmlnsxsd"http//www.w3.org/2001/XMLSchema"
- xmlnsSOAP-ENV"http//schemas.xmlsoap.org/SOAP/
envelope/" - xmlnsxsi"http//www.w3.org/2001/XMLSchema-inst
ance"gt
66Data Types
- The data type for a given value is never
undefined in SOAP - SOAP distinguished between simple types and
complex types - A simple type does not contain any named parts,
it just contains a single piece of data - Example string
- Example int
- A complex type contains multiple pieces of data
that have some relation to each other - Similar to structs or classes or arrays
- Individual pieces of data may be accessed by
using - an ordinal position in a sequence of values (like
arrays) - values that are keys to an associative array
(like hash tables) - the names of the constituent parts (like C
structs) - There is always a way to distinguish a specific
data value within a complex value - referred to as the "accessor"
- A names subcomponent of a complex type may be a
complex type itself
67Built-in Data Types
68References
- We briefly saw how to declare these in DTDs
- Let's see how to use these
- ltroundTableMembersgt
- ltmembergt
- ltnamegtKing Arthurlt/namegt
- ltpositiongtKinglt/positiongt
- lt/membergt
- ltmembergt
- ltnamegtSir Robinlt/namegt
- ltpositiongtKnightlt/positiongt
- ltkinggtKing Arthurlt/kinggt
- lt/membergt
- ltmembergt
- ltnamegtSir Galahadlt/namegt
- ltpositiongtKnightlt/positiongt
- ltkinggtKing Arthurlt/kinggt
- lt/membergt
- ...
69References
- References help you eliminate unnecessary
duplication (normalization) - ltroundTableMembersgt
- ltmember id"Arthur"gt
- ltnamegtKing Arthurlt/namegt
- ltpositiongtKinglt/positiongt
- lt/membergt
- ltmembergt
- ltnamegtSir Robinlt/namegt
- ltpositiongtKnightlt/positiongt
- ltking href"Arthur" /gt
- lt/membergt
- ltmembergt
- ltnamegtSir Galahadlt/namegt
- ltpositiongtKnightlt/positiongt
- ltking href"Arthur" /gt
- lt/membergt
- ...
70References
- May not save space if the data items are small
- Should save space if the data items are larger
- Are necessary to link objects.
- Graphs
- Organizational structure (like round table in
previous slide) - Students' class enrollment
71Indicating Type
- Every element that contains a value must also
indicate the type of the data - In SOAP, these types may be specified
- By using the xsitype attribute
- with a valid type identifier, such as xsdstring
or xsdint - By being an element of an array that already
constrains the type of its contents - By being related to some type that is defined in
an XML Schema - So far, we've only seen examples of the first
method - SOAP (by itself without WSDL), usually uses the
first method (and the second) - There are two different string type declarations
- xsdstring from XML Schema
- SOAP-ENCstring from SOAP Section 5
- This one allows for id and href attributes
72Indicating Type
- Example of dynamically declaring the type inside
the XML document itself - lt?xml version"1.0" encoding"UTF-8"?gt
- ltSOAP-ENVEnvelope ...
- ...
- ltSOAP-ENVBodygt
- ...
- ltlue xsitype"xsdint"gt42lt/luegt
- ltbq xsitype"xsdstring"gtWhat is your
color?lt/bqgt - ltbq xsitype"SOAP-ENCstring"gtColor?lt/bqgt
- ...
- lt/SOAP-ENVBodygt
- lt/SOAP-ENVEnvelopegt