Title: SOAP Simple Object Access Protocol
1SOAPSimple Object Access Protocol
2Purpose of SOAP
- Developers need to establish a standard transport
and data-exchange framework to achieve XML-based
interaction. - The reasons for using SOAP
- Web services require a protocol that uses a
standard, open data format. - Web services need a way to work with the basic
security mechanisms of remote networks.
3Nature of SOAP
- SOAP is a software system that enables
applications to communicate with one another
using XML-based message, called SOAP message. - SOAP messages encapsulate the information
exchanged. - SOAP messages dont provide programming
instructions, rather, specify the operations to
invoke. - SOAP supports features such as attachments,
security, routing information and transaction.
4Flow of a SOAP Request
Client-Side
Serialize
SOAP Message
Proxy
Consumer
Deserialize
Network
Server-Side
IIS
ASPNET_ISAPI.DLL
HTTP Handlers
Web Service
Deserialize
HTTP Web Service Handler
Serialize
5SOAP Specifications
- SOAP envelope describes the format of a SOAP
message. - The second part defines a set of rules that
encode data types. - The third part defines how a SOAP message can
execute remote procedure call (RPC). - The last part specifies the message binding
protocol. - HTTP, HTTPS, SMTP
6Anatomy of a SOAP Message
- A SOAP message is composed of an envelope that
contains the body of the message and any header
information used to describe the message. - The root element of the document is the Envelope
element. - The envelope can contain an optional Header
element, which contains information about the
message. - The envelope must contain one Body element.
7A SOAP Envelop
Header
A SOAP Envelop
Body
8SOAP Actors
- A SOAP actor is anything that acts on the content
of the SOAP message. - There are two types of SOAP actors
- The default actor is the intended final recipient
of a SOAP message. - An intermediary receives a SOAP message and might
act on the message before forwarding it along the
intended message path.
9Header Element
- The optional Header element is used to pass data
that might not be appropriate to encode in the
body. - Authentication, Security digest information,
Routing information, Transactions, Payment
information.
lt?xml version"1.0" encoding"utf-8"?gt ltsoapEnvel
ope xmlnssoap"http//schemas.xmlsoap.org/soap/en
velope/"gt ltsoapHeadergt ltDigestgtB839D234A3F8
7lt/Digestgt lt/soapHeadergt ltsoapBodygt
ltStockReportgt ltSymbolgtMSFTlt/Symbolgt
ltPricegt74.56lt/Pricegt lt/StockReportgt
lt/soapBodygt lt/soapEnvelopegt
10Body Element
- The body contains the payload of the message and
there are no restrictions on how the body can be
encoded. - SOAP messages are placed into two categories
- Procedure-oriented messages provide two-way
communication and are commonly referred to as
remote procedure call (RPC) messages. - Document-oriented messages generally facilitate
one-way communication. Business documents such as
purchase orders are examples of document-oriented
messages.
11SOAP 1.1 XML Schema Definition
ltxsschema xmlnsxs"http//www.w3.org/2001/XMLSch
ema" xmlnstns"http//schemas.xmlsoap.o
rg/soap/envelope/" targetNamespace"htt
p//schemas.xmlsoap.org/soap/envelope/" gt
lt!-- Envelope, header and body --gt ltxselement
name"Envelope" type"tnsEnvelope" /gt
ltxscomplexType name"Envelope" gt
ltxssequencegt ltxselement ref"tnsHeader"
minOccurs"0" /gt ltxselement ref"tnsBody"
minOccurs"1" /gt ltxsany namespace"other"
minOccurs"0" maxOccurs"unbounded"
processContents"lax" /gt lt/xssequencegt
ltxsanyAttribute namespace"other"
processContents"lax" /gt lt/xscomplexTypegt
12SOAP 1.1 XML Schema Definition
ltxselement name"Header" type"tnsHeader" /gt
ltxscomplexType name"Header" gt
ltxssequencegt ltxsany namespace"other"
minOccurs"0" maxOccurs"unbounded"
processContents"lax" /gt lt/xssequencegt
ltxsanyAttribute namespace"other"
processContents"lax" /gt lt/xscomplexTypegt
ltxselement name"Body" type"tnsBody" /gt
ltxscomplexType name"Body" gt ltxssequencegt
ltxsany namespace"any" minOccurs"0"
maxOccurs"unbounded" processContents"lax" /gt
lt/xssequencegt ltxsanyAttribute
namespace"any" processContents"lax" /gt
lt/xscomplexTypegt
13SOAP 1.1 XML Schema Definition
lt!-- Global Attributes --gt ltxsattribute
name"mustUnderstand" default"0" gt
ltxssimpleTypegt ltxsrestriction
base'xsboolean'gt ltxspattern value'01'
/gt lt/xsrestrictiongt lt/xssimpleTypegt
lt/xsattributegt ltxsattribute name"actor"
type"xsanyURI" /gt
14SOAP 1.1 XML Schema Definition
ltxssimpleType name"encodingStyle" gt
ltxslist itemType"xsanyURI" /gt
lt/xssimpleTypegt ltxsattribute
name"encodingStyle" type"tnsencodingStyle"
/gt ltxsattributeGroup name"encodingStyle" gt
ltxsattribute ref"tnsencodingStyle" /gt
lt/xsattributeGroupgt ltxselement name"Fault"
type"tnsFault" /gt ltxscomplexType
name"Fault" final"extension" gt
ltxssequencegt ltxselement name"faultcode"
type"xsQName" /gt ltxselement
name"faultstring" type"xsstring" /gt
ltxselement name"faultactor" type"xsanyURI"
minOccurs"0" /gt ltxselement
name"detail" type"tnsdetail"
minOccurs"0" /gt lt/xssequencegt
lt/xscomplexTypegt
15SOAP 1.1 XML Schema Definition
ltxscomplexType name"detail"gt ltxssequencegt
ltxsany namespace"any" minOccurs"0"
maxOccurs"unbounded" processContents"lax"
/gt lt/xssequencegt ltxsanyAttribute
namespace"any" processContents"lax" /gt
lt/xscomplexTypegt lt/xsschemagt
16SOAP Message Example
ltsoapEnvelope xmlnssoap"http//schemas.xmlsoap
.org/soap/envelope/"gt ltsoapBodygt
ltxTransferFunds xmlnsx"urnexamples-orgbanking
"gt ltfromgt22-342439lt/fromgt
lttogt98-283843lt/togt ltamountgt100.00lt/amountgt
lt/xTransferFundsgt lt/soapBodygt lt/soapEnvelopegt
17SOAP Message Example
ltsoapEnvelope xmlnssoap"http//schemas.xmlsoap
.org/soap/envelope/"gt ltsoapBodygt
ltxTransferFundsResponse xmlnsx"urnexamples-
orgbanking"gt ltbalancesgt ltaccountgt
ltidgt22-342439lt/idgt ltbalancegt33.45lt/balancegt
lt/accountgt ltaccountgt
ltidgt98-283843lt/idgt ltbalancegt932.73lt/balancegt
lt/accountgt lt/balancesgt
lt/xTransferFundsResponsegt lt/soapBodygt lt/soapEn
velopegt
18SOAP Message Example
ltsoapEnvelope xmlnssoap"http//schemas.xmlsoa
p.org/soap/envelope/"gt ltsoapBodygt
ltsoapFaultgt ltfaultcodegtsoapServerlt/faultcodegt
ltfaultstringgtInsufficient fundslt/faultstringgt
ltdetailgt ltxTransferError
xmlnsx"urnexamples-orgbanking"gt
ltsourceAccountgt22-342439lt/sourceAccountgt
lttransferAmountgt100.00lt/transferAmountgt
ltcurrentBalancegt89.23lt/currentBalancegt
lt/xTransferErrorgt lt/detailgt lt/ soapFault
gt lt/soapBodygt lt/soapEnvelopegt
19Procedure-oriented Messages
- Two SOAP messages are paired together to
facilitate an RPC method call with SOAP - the request message
- Information about the targeted method along with
any input parameters is passed to the server via
a request message. - the corresponding response message
- The server invokes some behavior (or procedure)
and returns the results and any return parameters.
20Document-oriented Messages
- A business document such as a purchase order or
an invoice can be encoded within the body of a
SOAP message and routed to its intended
recipient. - The recipient of the document might or might not
send an acknowledgment message back to the sender.
21SOAP RPC Messages
- Remote Procedure Call (RPC) is a technology by
which one application invokes a procedure
residing on another computer. - The SOAP message body contains the Web service
method to be invoked, any parameters the method
takes and the target procedures URI.
22SOAP Example
lt?xml version"1.0"?gt ltsoapEnvelope
xmlnssoap"http//schemas.xmlsoap.org/soap/envelo
pe/"gt ltsoapBodygt ltAddgt ltxgt1lt/xgt
ltygt2lt/ygt lt/Addgt lt/soapBodygt lt/soapEnvelop
egt
public int Add(int x, int y) return x
y
Add(1, 2)
lt?xml version"1.0"?gt ltsoapEnvelope
xmlnssoap"http//schemas.xmlsoap.org/soap/envelo
pe/"gt ltsoapBodygt ltAddResultgt
ltresultgt3lt/resultgt lt/AddResultgt
lt/soapBodygt lt/soapEnvelopegt
23SOAP Encoding
- SOAP Encoding defines the way data can be
serialized within a SOAP message. - SOAP Encoding builds on the types defined in the
XML specification. - Simple Types
- An instance of a data type is encoded as an XML
element. - integer called Age would be encoded
asltAgegt31lt/Agegt
24SOAP Encoding
- Compound Type Structures
- Each of the variables contained within the
instance of the structure is serialized as a
child element of the parameter element.
public struct RectSolid public int length
public int width public int height
public int CalcVolume(RectSolid r) return
(r.length r.width r.height)
lt?xml version"1.0" encoding"utf-8"?gt ltsoapEnvel
ope xmlnssoap "http//schemas.xmlsoap.org/soap/e
nvelope/"gt ltsoapBodygt ltCalcVolumegt
ltrgt ltlengthgt2lt/lengthgt
ltwidthgt3lt/widthgt ltheightgt1lt/heightgt
lt/rgt lt/CalcVolumegt lt/soapBodygt lt/soapEnvel
opegt
25SOAP Encoding
- Compound Type Array
- SOAP 1.1 specifies the encoding of Array type.
public int AddArray(int numbers) ...
int a 1, 2, 3 int total total
AddArray(a)
lt?xml version"1.0" encoding"utf-8"?gt ltsoapEnvel
ope xmlnssoap"http//schemas.xmlsoap.org/soa
p/envelope/" xmlnssoap-enc"http//schemas.xm
lsoap.org/soap/encoding/" xmlnsxsi"http//ww
w.w3.org/2001/XMLSchema-instance"gt ltsoapBodygt
ltAddArraygt lta soap-encarrayType"xsiint
3"gt ltintgt1lt/intgt ltintgt2lt/intgt
ltintgt3lt/intgt lt/agt lt/AddArraygt
lt/soapBodygt lt/soapEnvelopegt
26SOAP Encoding
public void RegisterTeams(string teams)
// ...
lt?xml version"1.0" encoding"utf-8"?gt ltsoapEnvel
ope xmlnssoap"http//schemas.xmlsoap.org/soa
p/envelope/" xmlnssoap-enc"http//schemas.xm
lsoap.org/soap/encoding/" xmlnsxsi"http//ww
w.w3.org/2001/XMLSchema-instance"gt ltsoapBodygt
ltRegisterTeamsgt ltteams
soap-encarrayType"xsistring3"gt ltteam
soap-encarrayType"xsistring3"gt
ltplayergtBoblt/playergt ltplayergtSuelt/player
gt ltplayergtMikelt/playergt
lt/teamgt ltteam soap-encarrayType"xsistri
ng2"gt ltplayergtJanelt/playergt
ltplayergtMarklt/playergt lt/teamgt
ltteam soap-encarrayType"xsistring4"gt
ltplayergtMarylt/playergt
ltplayergtJilllt/playergt
ltplayergtJimlt/playergt ltplayergtTomlt/player
gt lt/teamgt lt/teamsgt
lt/RegisterTeamsgt lt/soapBodygt lt/soapEnvelopegt
string teams new string3 teams0
new string3 teams00 "Bob" teams01
"Sue" teams02 "Mike" teams1 new
string2 teams10 "Jane" teams11
"Mark" teams2 new String4 teams20
"Mary" teams21 "Jill" teams22
"Jim" teams23 "Tom" RegisterTeams(teams)
27Passing Parameters by Reference
public void FibonacciIncrement(ref int n1, ref
int n2) int temp n2 n1 n2
n2 temp n1
lt!-- Request Message --gt lt?xml version"1.0"
encoding"utf-8"?gt ltsoapEnvelope
xmlnssoap"http//schemas.xmlsoap.org/soap/envelo
pe/"gt ltsoapBodygt ltFibonacciIncrementgt
ltn1gt1lt/n1gt ltn2gt1lt/n2gt
lt/FibonacciIncrementgt lt/soapBodygt lt/soapEnvelo
pegt
int x 1 int y 1 for(int i 1, i lt 11, i
2) Console.Write("0, 1", x, y)
FibonacciIncrement(x, y)
lt!-- Request Message --gt lt?xml version"1.0"
encoding"utf-8"?gt ltsoapEnvelope
xmlnssoap"http//schemas.xmlsoap.org/soap/envelo
pe/"gt ltsoapBodygt ltFibonacciIncrementRespons
egt ltn1gt2lt/n1gt ltn2gt3lt/n2gt
lt/FibonacciIncrementResponsegt
lt/soapBodygt lt/soapEnvelopegt
28Protocol Binding
- SOAP messages can be sent over any transport
protocol that is capable of carrying XML. - The SOAP specification describes only one
protocol binding sending SOAP messages via HTTP
POST. - It is firewall friendly.
- It has a robust supporting infrastructure.
- It is inherently stateless.
- It is simple.
- It maps nicely to RPC-style message exchanges.
- It is open.
29Protocol Binding
30HTTP Request
- Header contains information about the request
and about the client that sent the request. - Body follows the header and is delimited by two
carriage-return/linefeed pairs.
POST /SomeWebService HTTP/1.1 Content-Type
text/xml SOAPAction "http//somedomain.com/SomeW
ebService.wsdl" Content-Length 243 Host
sshort3 lt?xml version"1.0" encoding"utf-8"?gt
ltsoapEnvelope xmlnssoap"http//schemas.xmlso
ap.org/soap/envelope/" xmlnssoap-enc"http//sc
hemas.xmlsoap.org/soap/encoding/"gt ltsoapBodygt
ltAddgt ltxgt2lt/xgt ltygt2lt/ygt lt/Addgt
lt/soapBodygt lt/soapEnvelopegt