client-server
Download
Report
Transcript client-server
第六章 通讯与安全
龚 斌
山东大学计算机科学与技术学院
山东省高性能计算中心
网格通讯协议
•
•
•
•
XML远程过程调用XML-RPC
简单对象访问协议SOAP
WS-Routing
WS-Referral
XML远程过程调用XML-RPC
Client and Server have to
understand each other.
Client
Wieviel Uhr
ist es?
?
Server
Client and Server agree on a
common language.
Wieviel Uhr
ist es?
Client
What’s the
time?
Quelle heure est-il?
7pm!
Server
The client encodes the information in the
“common language”, the server decodes
the information. Decode
Encode
Wieviel Uhr
ist es?
Client
What’s the
time?
Quelle heure est-il?
Server
XML-RPC uses XML as a common
language to transmit data
Decode
Encode
Java
C++
Python
etc.
Client
XML
Java
C++
Python
etc.
Server
That explains the XML in XML-RPC
but what means RPC?
RPC means “Remote Procedure Call”,
that means you call a procedure (function)
on a different machine.
public class Example {
Local
public int sum(int a, int b) {
return a+b;
}
public static void main (String [] args) {
Example eg = new Example();
eg.sum(13,17);
}
}
procedure call
Remote procedure call (RPC)
Client
[…]
eg.sum(13,17);
[…]
RPC
Server
[…]
public int sum(int a, int b) {
return a+b;
}
[…]
RPC - Remote Procedure Call
• RPC is a powerful technique for constructing distributed, clientserver based applications.
• It is based on extending the notion of conventional, or local
procedure calling.
• As “remote” suggests, the called procedure need not to exist in the
same address space as the calling procedure.
– The two processes may be on the same system, or they may be
on different systems with a network connecting them.
• By using RPC, programmers of distributed applications avoid the
details of the interface with the network.
www.xmlrpc.com
What is XML-RPC?
• It's a spec and a set of implementations that allow
software running on disparate operating systems,
running in different environments to make
procedure calls over the Internet
• It's remote procedure calling using HTTP as the
transport and XML as the encoding. XML-RPC is
designed to be as simple as possible, while
allowing complex data structures to be transmitted,
processed and returned.
The specification, < 1800 words,
is lightweight and easy to learn.
Contains many examples.
• It's a spec and a set of implementations that allow
software running on disparate operating systems,
running in different environments to make
procedure calls over the Internet
• It's remote procedure calling using HTTP as the
transport and XML as the encoding. XML-RPC is
designed to be as simple as possible, while
allowing complex data structures to be transmitted,
processed and returned.
• It's a spec and a set of implementations that allow
software running on disparate operating systems,
running in different environments to make
Languages
include:
procedure
calls over
the Internet
C/C++,
Java,procedure
Perl, Python,
• It's remote
callingFrontier,
using HTTP as the
transport
XML as.NET,
the encoding.
Lisp,
PHP, and
Microsoft
Rebol,XML-RPC is
designed to be as simple as possible, while
Realallowing
Basic, complex
Tcl, Delphi,
WebObjects
data structures to be transmitted,
andreturned.
Zope
processed and
Uses existing protocols (HTTP) and a well
established framework (XML).
• It's a spec and a set of implementations that allow
software running on disparate operating systems,
running in different environments to make
procedure calls over the Internet
• It's remote procedure calling using HTTP as the
transport and XML as the encoding. XML-RPC is
designed to be as simple as possible, while
allowing complex data structures to be transmitted,
processed and returned.
The following data structures are
supported: integer, boolean, string, double,
date & time, base64 binaries, structs,
• It's a spec and a set of arrays.
implementations that allow
software running on disparate operating systems,
running in different environments to make
procedure calls over the Internet
• It's remote procedure calling using HTTP as the
transport and XML as the encoding. XML-RPC is
designed to be as simple as possible, while
allowing complex data structures to be transmitted,
processed and returned.
Example:
An XML-RPC client/server
application in Java.
• The Java package org.apache.xmlrpc provides classes to
implement an XML-RPC client and an XML-RPC server.
The package can be found at http://ws.apache.org/xmlrpc/
• A copy of the package is under the name cis69mc.jar on
Blackboard.
• To compile and run Java classes with the package, copy it
to your working directory and use the following commands
(in a DOS shell):
– javac -classpath ”cis69mc.jar;." xyz.java
– java -classpath ”cis69mc.jar;." xyz.java
(replace xyz by the name of your file)
import java.util.*;
import org.apache.xmlrpc.*;
A Java Client
public class JavaClient {
public static void main (String [] args) {
try {
XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2");
Vector params = new Vector();
params.addElement(new Integer(17));
params.addElement(new Integer(13));
Object result = server.execute("sample.sum", params);
int sum = ((Integer) result).intValue();
System.out.println("The sum is: "+sum);
} catch (Exception exception) {
System.err.println("JavaClient: " + exception);
}
}
}
A Java Client
import java.util.*;
import org.apache.xmlrpc.*;
public class JavaClient {
public static void main (String [] args) {
try {
XmlRpcClient server = new
• The Java package org.apache.xmlrpc
XmlRpcClient("http://localhost/RPC2");
contains classes for XML-RPC Java
Vector params = new Vector();
clients and XML-RPC server. E.g.
params.addElement(new Integer(17));
params.addElement(new Integer(13));
XmlRpcClient.
Object result = server.execute("sample.sum", params);
int sum = ((Integer) result).intValue();
System.out.println("The sum
is: "+sum);
• The
package java.util is necessary for
} catch (Exception exception) {
the Vector class.
System.err.println("JavaClient: " + exception);
}
}
}
A Java Client
import java.util.*;
import org.apache.xmlrpc.*;
public class JavaClient {
public static void main (String [] args) {
try {
XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2");
Vector params = new Vector();
• The Java package org.apache.xmlrpc
params.addElement(new Integer(17));
contains
classes for XML-RPC Java clients
params.addElement(new
Integer(13));
Object result = server.execute("sample.sum",
params);E.g. XmlRpcClient.
and XML-RPC server.
int sum = ((Integer) result).intValue();
The source code of this package is free.
System.out.println("The sum is: "+sum);
The package
java.util is necessary for the
} catch (Exception •exception)
{
System.err.println("JavaClient:
+ exception);
Vector "class.
java.util.Vector is part of the
}
Java distribution.
}
}
import java.util.*;
import org.apache.xmlrpc.*;
A Java Client
public class JavaClient {
public static void main (String [] args) {
try {
XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2");
Vector params = new Vector();
params.addElement(new Integer(17));
params.addElement(new Integer(13));
Object result = server.execute("sample.sum", params);
int sum = ((Integer) result).intValue();
• System.out.println("The
This line sends the
sumrequest
is: "+sum);to the server. The procedure
} catch
(Exception is
exception)
sum(17,13)
called{on the server as if it were a local
System.err.println("JavaClient:
+ exception);
procedure. The return" value
of a procedure call is always
}
an Object.
}
}• “sample” denotes a handler that is defined in the server.
import java.util.*;
import
org.apache.xmlrpc.*;
• The
parameters of
A Java Client
the procedure call are always
collected in a Vector.
public class JavaClient {
public static void main (String [] args) {
try {
XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2");
Vector params = new Vector();
params.addElement(new Integer(17));
params.addElement(new Integer(13));
Object result = server.execute("sample.sum", params);
int sum = ((Integer) result).intValue();
• System.out.println("The
This line sends the
sumrequest
is: "+sum);to the server. The procedure
} catch
(Exception is
exception)
sum(17,13)
called{on the server as if it were a local
System.err.println("JavaClient:
+ exception);
procedure. The return" value
of a procedure call is always
}
an Object.
}
}• “sample” denotes a handler that is defined in the server.
A Java Client
import java.util.*;
import org.apache.xmlrpc.*;
public class JavaClient {
public static void main (String [] args) {
try {
XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2");
Vector params = new Vector();
params.addElement(new
Integer(17));
• The XmlRpcClient
class is constructed by
params.addElement(new Integer(13));
specifying the “web address” of the server
Object result = server.execute("sample.sum", params);
machine
followed by /RPC2. E.g.
int sum = ((Integer)
result).intValue();
System.out.println("The
– localhost
sum is: "+sum);
- means the local machine.
} catch (Exception –exception)
{
An IP number,
e.g. 194.80.215.219
System.err.println("JavaClient: " + exception);
– A name, e.g. cis69.dyndns.org
}
– All of the above, followed by a port number, e.g.
}
}
cis69.dyndns.org:8080. The default port is 80.
A Java Client
•import
Asjava.util.*;
the result of the remote procedure call is always an
import
org.apache.xmlrpc.*;
Object
it has to be casted to the appropriate type (here:
Integer).
public class JavaClient {
public static void main (String [] args) {
try {
XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2");
Vector params = new Vector();
params.addElement(new Integer(17));
params.addElement(new Integer(13));
Object result = server.execute("sample.sum", params);
int sum = ((Integer) result).intValue();
System.out.println("The sum is: "+sum);
} catch (Exception exception) {
System.err.println("JavaClient: " + exception);
}
}
}
A Java Client
import java.util.*;
import org.apache.xmlrpc.*;
public class JavaClient {
public static void main (String [] args) {
try {
XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2");
• When problems occur (no
Vector params = new Vector();
connection, etc.) an
params.addElement(new Integer(17));
Exception is thrown and has
params.addElement(new Integer(13));
Object result = server.execute("sample.sum",
params);
to be caught.
int sum = ((Integer) result).intValue();
System.out.println("The sum is: "+sum);
} catch (Exception exception) {
System.err.println("JavaClient: " + exception);
}
}
}
Client
Server
<?xml version="1.0" encoding="ISO-8859-1"?>
<methodCall>
<methodName>sample.sum</methodName>
<params>
<param>
<value><int>17</int></value>
</param>
<param>
<value><int>13</int></value>
</param>
• This is what the client sends
</params>
to the server.
</methodCall>
import org.apache.xmlrpc.*;
A Java Server
public class JavaServer {
public Integer sum(int x, int y) {
return new Integer(x+y);
}
public static void main (String [] args) {
try {
WebServer server = new WebServer(80);
server.addHandler("sample", new JavaServer());
server.start();
} catch (Exception exception) {
System.err.println("JavaServer: " + exception);
}
}
}
import org.apache.xmlrpc.*;
A Java Server
public class JavaServer {
public Integer sum(int x, int y) {
return new Integer(x+y);
}
public static void main (String [] args) {
try {
WebServer server = new WebServer(80);
server.addHandler("sample", new JavaServer());
server.start();
} catch (Exception exception) {
System.err.println("JavaServer: " + exception);
• The package org.apache.xmlrpc contains
}
the class WebServer for a XML-RPC
}
Server implementation
}
import org.apache.xmlrpc.*;
A Java Server
public class JavaServer {
public Integer sum(int x, int y) {
return new Integer(x+y);
}
public static void main (String [] args) {
try {
WebServer server = new WebServer(80);
server.addHandler("sample", new JavaServer());
server.start();
• (Exception
The procedure
} catch
exception)that
{ is called remotely is
implemented as a"public
method in a class.
System.err.println("JavaServer:
+ exception);
} • An instance of this class is then associated
}
with a handler that is accessible by the
}
client.
A Java Server
import org.apache.xmlrpc.*;
• The server is initialised by the port number
(here: 80).
public class JavaServer {
public Integer •sum(int
int y) { starts to listen at port 80.
Thex,server
return new Integer(x+y);
}
public static void main (String [] args) {
try {
WebServer server = new WebServer(80);
server.addHandler("sample", new JavaServer());
server.start();
} catch (Exception exception) {
System.err.println("JavaServer: " + exception);
}
}
}
Client
Server
<?xml version="1.0" encoding="ISO-8859-1"?>
<methodResponse>
<params>
<param>
<value><int>30</int></value>
</param>
</params>
</methodResponse>
XML-RPC
• XML-RPC is a Remote Procedure Calling
protocol that works over the Internet. An
XML-RPC message is an HTTP-POST
request. The body of the request is in XML.
A procedure executes on the server and the
value it returns is also formatted in XML.
• Procedure parameters can be scalars,
numbers, strings, dates, etc.;
Request example
POST /RPC2 HTTP/1.0
User-Agent: Frontier/5.1.2 (WinNT)
The Header
Host: cis69.dyndns.com
Content-Type: text/xml
Content-length: 144
<?xml version="1.0"?>
<methodCall>
<methodName>examples.name</methodName>
<params>
<param>
<value><i4>41</i4></value>
examples.name(41)
</param>
</params>
</methodCall>
Header requirements
• The format of the URI in the first line of the header is not specified.
For example, it could be empty, a single slash, if the server is only
handling XML-RPC calls. However, if the server is handling a mix
of incoming HTTP requests, we allow the URI to help route the
request to the code that handles XML-RPC requests. (In the
example, the URI is /RPC2, telling the server to route the request to
the "RPC2" responder.)
• A User-Agent and Host must be specified.
• The Content-Type is text/xml.
• The Content-Length must be specified and must be correct.
Payload (有效载荷)format
• The payload is in XML, a single <methodCall> structure.
• The <methodCall> must contain a <methodName> sub-item, a
string, containing the name of the method to be called. The string
may only contain identifier characters, upper and lower-case A-Z,
the numeric characters, 0-9, underscore, dot, colon and slash. It's
entirely up to the server to decide how to interpret the characters
in a methodName.
• For example, the methodName could be the name of a file
containing a script that executes on an incoming request. It could
be the name of a cell in a database table. Or it could be a path to a
file contained within a hierarchy of folders and files.
• If the procedure call has parameters, the <methodCall> must
contain a <params> sub-item. The <params> sub-item can contain
any number of <param>s, each of which has a <value>.
Scalar <value>s
• <value>s can be scalars, type is indicated by nesting the value inside
one of the tags:
• <i4> or <int> (four-byte signed integer), e.g: 3, 888, -12, 0
• <boolean> , e.g. 0 (false) or 1 (true)
• <string> , e.g. hello world, Marc Conrad
• <double> (floating point number), e.g. -12.214
• <dateTime.iso8601> (date/time) 20031017T14:08:55
• <base64> (base64-encoded binary) eW91IGNhbidpcyE=
If no type is indicated, the type is string.
A value can also be of type <struct>.
• A <struct> contains <member>s and each <member> contains
a <name> and a <value>.
• Example of a two-element <struct>:
<struct>
<member>
<name>lowerBound</name>
<value><i4>18</i4></value>
</member>
lowerBound: 18
<member>
upperBound: 139
<name>upperBound</name>
<value><i4>139</i4></value>
</member>
</struct>
A value can also be of type <array>.
• An <array> contains a single <data> element, which can
contain any number of <value>s.
• Here's an example of a four-element array:
<array>
<data>
<value><i4>12</i4></value>
<value><string>Egypt</string></value>
<value><boolean>0</boolean></value>
<value><i4>-31</i4></value>
</data>
[12,”Egypt”,false,-31]
</array>
Here's an example of a response to an XMLRPC request:
HTTP/1.1 200 OK
Connection: close
Content-Length: 134
Content-Type: text/xml
Date: Fri, 17 Jul 1998 19:55:08 GMT
Server: UserLand Frontier/5.1.2-WinNT
“Luton, LU1 3JU”
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><string>Luton, LU1 3JU</string></value>
</param>
</params>
</methodResponse>
Response format
• Unless there's a lower-level error, always return 200 OK.
• The Content-Type is text/xml. Content-Length must be present and
correct.
• The body of the response is a single XML structure, a
<methodResponse>, which can contain a single <params> which
contains a single <param> which contains a single <value>.
• The <methodResponse> could also contain a <fault> which contains
a <value> which is a <struct> containing two elements, one named
faultCode, an <int> and one named faultString, a <string>.
Fault example
<?xml version="1.0"?> <methodResponse>
<fault>
faultCode: 4
<value>
faultString: Overflow
<struct>
<member>
<name>faultCode</name>
<value><int>4</int></value>
</member>
<member>
<name>faultString</name>
<value><string>Overflow</string> </value>
</member>
</struct>
</value>
</fault>
Copyright of the Specification
• © Copyright 1998-2003 UserLand Software. All Rights Reserved.
• This document and translations of it may be copied and furnished to
others, and derivative works that comment on or otherwise explain it
or assist in its implementation may be prepared, copied, published
and distributed, in whole or in part, without restriction of any kind,
provided that the above copyright notice and these paragraphs are
included on all such copies and derivative works.
Copyright of the Specification
(cont’d)
• This document may not be modified in any way, such as by
removing the copyright notice or references to UserLand or other
organizations. Further, while these copyright restrictions apply to the
written XML-RPC specification, no claim of ownership is made by
UserLand to the protocol it describes. Any party may, for
commercial or non-commercial purposes, implement this protocol
without royalty or license fee to UserLand. The limited permissions
granted herein are perpetual and will not be revoked by UserLand or
its successors or assigns.
简单对象访问协议SOAP
What is a Web Service?
Web services are a new breed(种类) of Web application. They
are self-contained, self-describing, modular applications
that can be published, located, and invoked across the Web.
Web services perform functions, which can be anything
from simple requests to complicated business
processes...Once a Web service is deployed, other
applications (and other Web services) can discover and
invoke the deployed service.
[ http://www6.software.ibm.com/developerworks/education/wsbasics/ ]
What is SOAP?
• Simple Object Access Protocol
SOAP is a lightweight protocol for exchange of information in a
decentralized, distributed environment. It is an XML based
protocol that consists of three parts: an envelope that defines a
framework for describing what is in a message and how to process
it, a set of encoding rules for expressing instances of applicationdefined datatypes, and a convention for representing remote
procedure calls and responses. SOAP can potentially be used in
combination with a variety of other protocols; however, the only
bindings defined in this document describe how to use SOAP in
combination with HTTP and HTTP Extension Framework.
[ http://www.w3.org/TR/SOAP/ (1.1)]
What is SOAP 1.2?
• Simple Object Access Protocol
SOAP version 1.2 is a lightweight protocol for exchange of
information in a decentralized, distributed environment. It is an
XML based protocol that consists of four parts: an envelope that
defines a framework for describing what is in a message and how
to process it, a transport binding framework for exchanging
messages using an underlying protocol, a set of encoding rules for
expressing instances of application-defined data types and a
convention for representing remote procedure calls and responses.
Part 1 (this document) describes the SOAP envelope and SOAP
transport binding framework; Part 2[1]describes the SOAP
encoding rules, the SOAP RPC convention and a concrete HTTP
binding specification.
[ http://www.w3.org/TR/soap12-part1/ (1.2 Working Draft)]
History of SOAP
• SOAP 0 (1998)
– Microsoft, DevelopMentor
• XML-RPC (1998)
– Subset of SOAP
• ebXML (1999)
– Electronic Business XML
– Messaging for multiparty transactions
• SOAP 1.0 & 1.1 (2000)
• SOAP 1.2 (2001 working draft)
– Messaging and RPC
SOAP Node
•
•
•
•
Sender
Receiver
Intermediaries
Actors (v1.1)
SOAP Message
• Envelope
• Header
– actor attribute
– mustUnderstand attribute
• Body
• Fault
– Fault Code
•
•
•
•
•
VersionMismatch
MustUnderstand
DataEncodingUnknown
Client
Server
Example SOAP Message
<env:Envelope
xmlns:env="http://www.w3.org/2001/09/soapenvelope">
<env:Header>
<n:alertcontrol
xmlns:n=http://example.org/alertcontrol>
<n:priority>1</n:priority>
<n:expires>2001-06-22T14:00:0005: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>
Java and XML
• XML makes data portable
• Java makes code portable
Java API’s for XML
• JAXP : Java API for XML Processing
– SAX : Simple API for XML Processing
– DOM : Document Object Model
• JAXB : Java API for XML Binding
• JAXM : Java API for XML Messaging
– SOAP 1.1
• JAXR : Java API for XML Registries
WS-Routing
Why WS-Routing?
• SOAP (by itself) doesn’t define a message path
– Header blocks describe functions to be performed by
intermediaries that play specified roles, but there is no
standard way to provide addresses of intermediaries or
indicate the order in which intermediaries are to be visited
– Envelope doesn’t contain address (target module, target node)
• Hence, SOAP message is embedded in another
application layer protocol - generally HTTP - that
contains the address
– receiving (HTTP) processor directs message to target
(application) module
– Target module determines next node and addresses the HTTP
message to it
Why WS-Routing?
• WS-Routing extends SOAP with an addressing
structure to define a complete message path
• Extended SOAP message is self-contained
– does not have to be bound to another application layer
protocol
– can be sent directly over a transport protocol (e.g., TCP)
– receiving SOAP processor directs message to target module
– target module interprets WS-Routing information and sends
message to next intermediary using transport protocol
WS-Routing
• 允许开发者定义SOAP消息的静态路由信
息
A
B
C
D
E
To: E
To: E
To: E
To: E
From: A
From: A
From: A
From: A
Fwd:B-C-D
Fwd: C-D
Fwd: D
Fwd:B-C-D
rev
Rev: B
Rev: C-B
Rev:D-C-B
<S:Envelop>
<S:Header>
<m:path cmlns:m=http://schemas.xmlsoap.org/rp/
S:actor=http://schemas.xmlsoap.org/soap/actor/next
S:mustUnderstand=“1”>
<m:action>http://soapinterop.org/</m:action>
<m:to>http://E.com/route</m:to>
<m:id>uuid:09233523-345b-4351-b623-5dsf35sgs5d6</m:id>
<m:fwd>
<m:via>http://B.com/route</m:via>
<m:via>http://C.com/route</m:via>
<m:via>http://D.com/route</m:via>
</m:fwd>
<m:rev>
<m:via/>
</m:rev>
<m:from>mailto:[email protected]</m:from>
</m:path>
</S:header>
<S:Body>
…..
</S:Body>
</S:Envelope>
WS-Routing主要元素含义
To
描述消息的最终接受者的位置
Fwd
正向消息的路径,其中包含经过的所有中间结点,包含的每
个节点用via元素标注
Rev
描述消息返回的路径,也就是反向消息的路径
Via
说明消息经过的中间结点,该元素在fwd中的顺序表示中间结
点的先后顺序
From
指明消息的发送者,消息的发送者可能是一个应用程序,也
可能是一个人,在通常情况下,from中包含的是负责发出该
消息的人的E-mail地址
id
表示该消息在网上的唯一标示符,在消息从发送者发出到接
受者接受到的整个过程中,该标示符必须是唯一的
WS-Routing
• WS-Routing:
– is stateless: nodes along path do not maintain
state
– defines a SOAP header for storing routing
information
– supports
• Specification of a forward path
• Specification of a reverse path
• Specification of relationships (correlation) between
messages
Intermediaries
• Support a distributed processing mechanism
in which nodes along a message path supply
value-added services
– SOAP header contains the part of a message to
be processed by an intermediary that fulfills a
particular role
Specifying the Message Path
•
•
•
•
<path> - WS-Routing (SOAP) header block
<from> - URI of initial sender
<to> - URI of final destination
<fwd> - specifies forward message path
using an ordered list of <via> elements
– <via> - URI of an intermediate
• <rev> - (optional) specifies reverse message
path using an ordered list of <via> elements
WS-Routing Processing
• Final destination is the <to> (if present) or the last
<via> child of <fwd> element
• On receipt of message, a node deletes the first
<via> child of <fwd>, processes appropriate
header blocks, and relays message to new first
<via> child of <fwd>, or to <to> element if <fwd>
has no children
• A node may insert new <via> children to
dynamically build the forward path
Message Format
<s:Envelope xmlns:s=“…”
<s:Header>
<m:path xmlns:m=“… WS-Routing namespace …”>
<m:action> …URI identifying processor at destination…</m:action>
<m:to> … URI identifying final destination … </m:to>
<m:fwd>
<m:via> … URI identifying first intermediary … </m:via>
<m:via> … URI identifying second intermediary … </m:via>
… additional intermediaries can be specified here …
</m:fwd>
<m:from> … URI identifying initial sender … </m:from>
<m:id> … unique message identifier …</m:id>
</m:path>
… other headers …
</s:Header>
<s:Body> …. </s:Body>
</s:Envelope>
Reverse Path
• In some applications it may be appropriate to
provide for a response message
–
–
–
–
Communication follows request/response pattern
Peer-to-peer communication is anticipated
A fault message may be generated
An acknowledgement will be sent
• Problem: Don’t want intermediate nodes to
have to maintain state to remember the reverse
path
Reverse Path
• Solution: Sender includes a <rev> child of
<path> element in forward message
– Reverse path is built dynamically and stored in
message as it progresses in forward direction
– Indicates a possible path to be used by receiver for
a return message
• Intermediary may short-circuit forward path
and reply to initial sender over the (partial)
reverse path
– Appropriate if intermediary implements a cache
Building the Reverse Path
• When an intermediary receives a message
containing a <rev> element it adds a new
<via> element as the head of the <rev> list
containing its own URI.
Constructing the Reverse Path
<m:path …>
….
<m:fwd>
<m:via>…B’s URI…</m:via>
<m:via>…C’s URI…</m:via>
</m:fwd>
<m:rev>
<m:via>…A’s URI…</m:via>
</m:rev>
….
</m:path>
message arriving
at B from A
<m:path …>
….
<m:fwd>
<m:via>…C’s URI…</m:via>
</m:fwd>
<m:rev>
<m:via> …B’s URI…</m:via>
<m:via> …A’s URI…</m:via>
</m:rev>
….
</m:path>
message leaving
B addressed to C
Message Correlation
• <m:relatesTo> can be used to store the
value of the <m:id> field of a related
message
– A reply message is related to a forward message
– A fault message is related to the message that
caused the fault
WS-referral
WS-Referral
• 基于SOAP的协议
• 用来配置SOAP路由器中关于消息路径的
信息,提供如何配置SOAP路由器以便建
立一个消息路径的方法
• WS-Routing:提供描述消息实际路径的
机制
• WS-Referral则提供建立这种消息路径机
制的配置方法
WS-Referral
• 允许开发者定义SOAP消息的动态路由信
息
• For…if…then go via
•for any SOAP actor name matching the set of
SOAP actors listed in the for element
•if the set of conditions listed in the if element is
met and hence the statement is satisfied
•then go via one of the SOAP routers listed in the
go element
WS-Referral主要元素的含义
For
指定WS-Referral语句作用的SOAP消息动作者的集合,
这样可以确定一个特定的SOAP消息是否属于该语句
的作用范围
If
包含一组结构元素的条件表达式,只有满足该条件,
WS-Referral语句才起作用,目前的规范中定义了两
个基本的条件ttl和invalidates
Go
如果一个SOAP消息的消息头标示为该消息要发祥一
个URI,而且满足一组条件,那么通过go元素中罗列
的某一个SOAP路由器发送该消息
desc
是可选元素,包含一些对接受者可能有用的信息,
这些信息对WS-Refeeral语句本身是否起作用并没有
影响。Desc元素携带一些接受者可选用的信息
例子1
<r:ref xmlns:r="http://schemas.xmlsoap.org/ws/2001/10/referral">
<r:for>
<r:exact>soap://example.org/some.doc</r:exact>
<r:prefix>soap://example.org/topics/icebergs</r:prefix>
</r:for>
<r:if>
<r:ttl>43200000</r:ttl>
</r:if>
<r:go>
<r:via>soap://example.com/mirror</r:via>
</r:go>
<r:refId>uuid:09233523-345b-4351-b623-5dsf35sgs5d6</r:refId>
<r:desc>
<r:refAddr>http://example.com/references/2001/10/1234.xml</r:refAddr>
</r:desc>
</r:ref>
例子2
<r:ref xmlns:r="http://schemas.xmlsoap.org/ws/2001/10/referral">
<r:for>
<r:prefix>soap://b.org</r:prefix>
</r:for>
<r:if/>
<r:go>
<r:via>soap://c.org</r:via>
</r:go>
<r:refId>mid:[email protected]</r:refId>
</r:ref>
例子3
<r:ref xmlns:r="http://schemas.xmlsoap.org/ws/2001/10/referral">
<r:for>
<r:prefix>soap://b.org/some/part</r:prefix>
</r:for>
<r:if/>
<r:go>
<r:via>soap://c.org/my/application</r:via>
</r:go>
<r:refId>mid:[email protected]</r:refId>
</r:ref>