Upload
ruth-james
View
228
Download
0
Tags:
Embed Size (px)
Citation preview
168493: XML and Web Services (II/2546)
2
Web Services Interaction Diagram
Request WSDL location
UDDI Registry
1
Download WSDL WSDL
Send SOAP messagesWith XML documents Web
Services
2
3
168493: XML and Web Services (II/2546)
3
Why Do We Need SOAP? An acceptable standard for
routing and packaging XML data exchanged between two applications on a network
No need to define our own networking, addressing, and routing protocols
168493: XML and Web Services (II/2546)
4
What is SOAP? Simple Object Access Protocol It defines a standard packaging
format for transmitting XML data between applications on a network
It is not specific to any programming language, product, or hardware platform
168493: XML and Web Services (II/2546)
5
What is SOAP? SOAP is not a programming
language or a business application component for building business applications
SOAP is intended for use as a portable communication protocol to deliver SOAP messages, which have to be created and processed by an application
168493: XML and Web Services (II/2546)
6
A SOAP Message A SOAP message is just an XML
document The message might be sent from
one application to another to synchronize contact information on two different systems
SOAP takes advantages of XML namespaces and XML schemas
168493: XML and Web Services (II/2546)
7
Anatomy of a SOAP Message
The structural format of a SOAP message contains the following elements Envelope Header (optional) Body Attachments (optional)
168493: XML and Web Services (II/2546)
8
SOAP Envelope The SOAP envelope is the
primary container of a SOAP message’s structure
It is the mandatory element of a SOAP message
It is represented as the root element of the message as Envelope
168493: XML and Web Services (II/2546)
9
SOAP Envelope Example<SOAP-ENV:Envelope
xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/”xmlns:xsi=“http://www.w3c.org/2001/XMLSchema-instance”
xmlns:xsd=“http://www.w3.org/2001/XMLSchema”
SOAP-ENV:encoding=“http://schemas.xmlsoap.org/soap/encoding/”>
<!– SOAP Header element --><!– SOAP Body element ---/>
</SOAP-ENV:Envelope>
168493: XML and Web Services (II/2546)
10
SOAP Header The SOAP header is represented
as the first immediate child element of a SOAP envelope
The Header element can also contain other attributes, such as mustUnderstand actor
168493: XML and Web Services (II/2546)
11
SOAP Header Example <SOAP-ENV:Header>
<wiley:Transactionxmlns:wiley=“http://jws.wiley.com/2002/booktx” SOAP-ENV:mustUnderstand=“1”>
<keyValue>5</keyValue></wiley:Transaction>
</SOAP-ENV:Header>
168493: XML and Web Services (II/2546)
12
SOAP Fault Example1<SOAP-ENV:Fault>
<faultcode>SOAP-Env:MustUnderstand</faultcode><faultstring>Header element missing</faultstring><faultactor>http://jws.wiley.com/GetBookPrice</faultactor><detail>…</detail>
</SOAP-ENV:Fault>
168493: XML and Web Services (II/2546)
13
SOAP Body A SOAP envelope contains a
SOAP body as its child element A Body block of a SOAP message
can contain any of the following: RPC method and its parameters Target application (receiver)
specific data SOAP fault for reporting errors and
status information
168493: XML and Web Services (II/2546)
14
SOAP Body Example<SOAP-ENV:Body>
<m:GetBookPricexmlns:m=“http://www.wiley.com/
jws.book.priceList/”><bookname xsi:type=‘xsd:string’>
Developing Java Web Services</bookname></m:getBookPrice>
</SOAP
168493: XML and Web Services (II/2546)
15
SOAP Fault In a SOAP message, the SOAP
Fault element is used to handle errors and to find out status information.
This element provides the error and /or status information
It can be used within a Body element or as a Body entry
168493: XML and Web Services (II/2546)
16
SOAP Fault It provides the following elements to
define the error and status of the SOAP message Faultcode: The faultcode element defines
the algorithmic mechanism for the SOAP application to identify the fault
Faultstring: The faultstring element provides a readable description of the SOAP fault
Faultactor: The faultactor element provides the information about the ultimate SOAP actor
Detail: The detail element
168493: XML and Web Services (II/2546)
17
SOAP Fault Example1<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode><faultstring>Server OS Internal Failure – Reboot server</faultstring><faultactor>http://abzdnet.net/keysoap.asp</faultactor>
</SOAP-ENV:Fault>
168493: XML and Web Services (II/2546)
18
SOAP Fault Example2 <SOAP-ENV:Fault>
<faultcode>Client</faultcode><faultstring>Invalide Request</faultstring><faultactor>http://jws.wiley.com/GetCatalog</faultactor>
</SOAP-ENV:Fault>
168493: XML and Web Services (II/2546)
19
SOAP mustUnderstand The SOAP understand attribute
indicates that the processing of a SOAP header block is mandatory (the attribute value is 1) or optional (the attribute value is 0) at the target SOAP node
<SOAP-ENV:Header><wiley:Catalog SOAP-ENV:mustUnderstand=“1”/>
</SOAP-ENV:Header>
168493: XML and Web Services (II/2546)
20
SOAP Fault Example3<SOAP-ENV:Body>
<SOAP-ENV:Fault><faultcode>SOAP-
Env:MustUnderstand</faultcode><faultstring>Could not
understand Header element</faultstring></SOAP-ENV:Fault>
</SOAP-ENV:Fault>
168493: XML and Web Services (II/2546)
21
SOAP Attachments A SOAP message contains the
primary SOAP envelope in an XML format and SOAP attachments in any data format that can be ASCII or binary
SOAP attachments are not part of the SOAP envelope but are related to the message
168493: XML and Web Services (II/2546)
22
SOAP Attachments The SOAP attachment part of the
message is contained to a MIME boundary (defined in the Context-Type header)
Each MIME part in the structure of the SOAP message is referenced using either Content-ID or Content-Location as labels for the part
168493: XML and Web Services (II/2546)
23
SOAP Attachments Both the SOAP header and body of
the SOAP message also can refer to these labels in the message
Each attachment of the message is identified with a Content-ID (typically an href attribute using a URL scheme) or Content-Location (a URI reference associated to the attachment)
168493: XML and Web Services (II/2546)
24
SOAP Attachment in a MIME
Structure
MIME-Version: 1.0Content-Type: Multipart/Related;boundary=MIME_boundary;
type=text/xml;Content-Description: SOAP
message description
168493: XML and Web Services (II/2546)
25
SOAP Attachment in a MIME Structure
--MIME_boundary --Content-Type: text/xml; charset=UTF-8Content-Transfer-Encoding: 8bitContent-ID:
<http://jws.wiley.com/coverpagedetails.xml>
Content-Location: http://jws.wiley.com/coverpagedetails.xml
168493: XML and Web Services (II/2546)
26
SOAP Attachment in a MIME Structure
<?xml version=‘1.0’?><SOAP-ENV:Envelopexmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/”>
<SOAP-ENV:Body></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
168493: XML and Web Services (II/2546)
27
SOAP Attachment in a MIME Structure
-- MIME_boundary --Content-Type: image/gifContent-Transfer-Encoding: binaryContent-ID:
<http://jws.wiley.com/DevelopingWebServices.gif>
Content-Location: http://jws.wiley.com/DevelopingWebServices.gif
<!-- … binary GIF image … -->--MIME_boundary --
168493: XML and Web Services (II/2546)
28
What is MIME? MIME: Multipurpose Internet Mail
Extension A standard system for identifying the
type of data contained in a file based on its extension.
MIME is an Internet protocol that allows you to send binary files across the Internet as attachments to e-mail messages. This includes graphics, photos, sound and video files, and formatted text documents.
168493: XML and Web Services (II/2546)
29
SOAP Encoding The SOAP Encoding defines a set of
rules for exposing its data types SOAP encoding also defines
serialization rules for its data model using an encodingStyle attribute
SOAP encoding supports both simple- and compound-type values
168493: XML and Web Services (II/2546)
30
SOAP Encoding Example Simple Type Values
The definition of simple type values is based on the W3C XML Schema specification
Examples <int>98765</int> <decimal>98675.43</decimal> <string>Java Rules</string>
168493: XML and Web Services (II/2546)
31
SOAP Encoding Example Array Types: example<MyPortfolio
xmlns=http://www.w3.org/2001/XMLSchema xmls:enc=“http://schemas.xmlsoap.org/soap/encoding” enc:arrayType=“xs:string[2]”><symbol>SUNW</symbol><symbol>IBM</symbol>
</MyPortfolio>
168493: XML and Web Services (II/2546)
32
SOAP Message Exchange Model SOAP is a stateless protocol used
to exchange messages between SOAP applications on a network, usually an intranet or the Internet
A SOAP application is simply any piece of software that generates or processes SOAP messages
168493: XML and Web Services (II/2546)
33
SOAP Message Exchange Model For example, any Java application or
J2EE component that uses JAX-RPC would be considered a SOAP application Because JAX-RPC is used to generate and
process SOAP message The application sending a SOAP
message is called the sender and the application receiving it is called the receiver
168493: XML and Web Services (II/2546)
34
SOAP Message Exchange Model
As a SOAP message travels along the message path, its header blocks may be intercepted and processed by any number of SOAP intermediaries along the way
A SOAP intermediary is both a receiver and a sender
168493: XML and Web Services (II/2546)
35
SOAP Message Exchange Model
The applications along the message path (the initial sender, intermediaries, and ultimate receiver) are called SOAP nodes
Initial Sender
Sender
SOAP SOAP SOAP
Ultimate receiver
ReceiverIntermediaries
168493: XML and Web Services (II/2546)
36
SOAP Message Exchange Model
SOAP SOAP SOAP
Ultimate receiver
ShippingNode
Initial Sender
Customer Node
SalesNode
InventoryNode
Intermediaries
168493: XML and Web Services (II/2546)
37
SOAP Actor The SOAP actor global attribute
with a URI value can be used in the Header element
SOAP defines an actor with a URI value, which identifies the name of the SOAP receiver node as an ultimate destination
168493: XML and Web Services (II/2546)
38
SOAP Actor Example<SOAP-ENV:Header>
<b:Name xmlns:b=“http://www.wiley.com/BookService/” SOAP-ENV:actor=“http://www.wiley.com/jws/” SOAP-ENV:mustUnderstand=“1”>WebServices</b:Name>
</SOAP-ENV:Header>
168493: XML and Web Services (II/2546)
39
SOAP Communication To enable communication between
SOAP nodes, SOAP supports the following two types of communication models SOAP RPC: It defines a remote procedural
call-based synchronous communication SOAP Messaging: It defines a document-
driven communication where SOAP nodes send and receive XML-based documents using synchronous and asynchronous messaging
168493: XML and Web Services (II/2546)
40
SOAP RPC The SOAP RPC representation
defines a tightly coupled communication model based on requests and responses
Using RPC conventions, the SOAP message is represented by method names with zero or more parameters and return values
168493: XML and Web Services (II/2546)
41
SOAP Request RPC-Based
<SOAP-ENV:Body><m:GetBookPricexmlns:m=“http://www.wiley.com/jws.book.priceList”>
<bookname xsi:type=‘xsd:string’>Developing Java Web Services</bookname></m:getBookPrice>
</SOAP-ENV:Body>
168493: XML and Web Services (II/2546)
42
SOAP Response RPC-Based
<SOAP-ENV:Body><m:GetBookPriceResponse xmlns:m=“http://www.wiley.com/jws.book.priceList”>
<price>50.00</price></m:GetBookPriceResponse>
</SOAP-ENV:Body>
168493: XML and Web Services (II/2546)
43
SOAP Messaging SOAP Messaging represents a
loosely coupled communication model based on message notification and the exchange of XML documents
The SOAP sender node sends a message with an XML document as its body message and the SOAP receiver node processes it
168493: XML and Web Services (II/2546)
44
SOAP Message-Based<env:Envelope
xmlns:env=“http://www.w3.org/2001/12/soap-envelope”>
<env:Header><n:InventoryNotice xmlns:n=“http://jws.wiley.com/Inventory”>
<n:productCode>J687</n:productCode></n:InventoryNotice>
</enve:Header>
168493: XML and Web Services (II/2546)
45
SOAP Message-Based<env:Body>
<m:product xmlns:m=“http://jws.wiley.com/product”>
<m:name>Developing Java Web Services</m:name>
<m:quantity>25000</m:quantity><m:date>2002-07-01</m:date>
</env:Body></env:Envelope>
168493: XML and Web Services (II/2546)
46
SOAP Bindings for Transport
Protocols The SOAP specifications do not
specify and mandate any underlying protocols between the SOAP nodes
SOAP can be used over a variety of transport protocols, such as HTTP, SMTP, POP3 and FTP
168493: XML and Web Services (II/2546)
47
SOAP Request Message Using HTTP
POST /GetBookPrice HTTP/1.1User Agent: Mozilla/4.0 (Linux)Host: krunapon:8080Content-Type: text/xml; charset=“utf-
8”Content-length: 546SOAPAction “/GetBookPrice<?xml version=“1.0”?>
<SOAP-ENV:Envelope>....</SOAP-ENV:Envelope>
168493: XML and Web Services (II/2546)
48
SOAP Response Message Using HTTP
HTTP/1.1 200 OKConnection: closeContent-Length: 524Content-Type: text/xml; charset=“utf-
8”Date: Fri, 3 May 2002 05:05:04 GMTServer: Apache/1.3.0<?xml version=“1.0”?>
<SOAP-ENV:Envelope>…</SOAP-ENV:Envelope>
168493: XML and Web Services (II/2546)
49
SOAP Message Exchange Patterns
The most common SOAP messaging patterns are as follows One-way message. The SOAP client
application sends SOAP messages to its SOAP server without any response being returned
Request/response exchange. In this pattern, the SOAP client sends a request message that results in a response message from the SOAP server to the client
168493: XML and Web Services (II/2546)
50
SOAP Message Exchange Patterns
Common SOAP messaging patterns Request/N*Response pattern. It is similar
to a request/response pattern, except the SOAP client sends a request that results in zero to many response messages from the SOAP server to the client
Notification pattern. The SOAP server sends messages to the SOAP client like an event notification, without regard to a response
168493: XML and Web Services (II/2546)
51
SOAP Message Exchange Patterns
Common SOAP messaging patterns Solicit-response pattern. The SOAP
server sends a request message to the SOAP client like a status checking or an audit and the client sends out a response message
168493: XML and Web Services (II/2546)
52
SOAP Message Exchange Patterns
SOAPClient
SOAPServer
SOAP Request Message
SOAP Response Message
SOAP Client SOAPClient
SOAPServer
SOAP Message
One-way message pattern
Request/Response pattern
SOAPClient
168493: XML and Web Services (II/2546)
53
SOAP Message Exchange Patterns
SOAPClient
SOAPServer
SOAP Request Message
SOAP Response Message
SOAP Response Message
Request/N*Response pattern
168493: XML and Web Services (II/2546)
54
SOAP Message Exchange Patterns
SOAPServer
SOAP Message(s)
Notification pattern
SOAPClient
SOAPClient
SOAPServer
SOAP Message
SOAP Response Message
Solicit-response pattern