Python 7.0pl5 Benutzerhandbuch

Seite von 124
The XML-RPC Gateway
119
port = 8000
group = "web-services"
httpd = netsvc.HttpDaemon(port)
rpcgw = netsvc.xmlrpc.RpcGateway(group)
httpd.attach("/service",rpcgw)
httpd.start()
dispatcher.run()
If you do decide to rely upon the XML-RPC protocol instead of the NET-RPC protocol, you will be
constrained as to what types you can use. This is because the XML-RPC protocol has a more limited
set of core types and is not type extendable as is the NET-RPC protocol. One major deficiency of the
XML-RPC protocol, is that it has no way of passing a null value, such as that implemented by the Py-
thon
None
type. Some XML-RPC clients have been extended to support a null value, but this gateway
does not implement such an extension.
A further complication which can arise in using XML-RPC is that the specification isn’t precise in cer-
tain areas. Although an XML-RPC message is notionally XML, the specification indicates use of AS-
CII values in strings only. This is in conflict with XML which requires at least UTF-8. Another issue
is that the XML-RPC specification mentions nothing about needing to support XML comments, CDA-
TA or various other XML constructs. This has lead to some implementations of the protocol not sup-
porting such features of XML and others relying on them.
Because of the inter operability issues which may arise due to the differences between different XML-
RPC clients, a number of different XML-RPC protocol implementations are actually supported by the
XML-RPC gateway. By default a pure Python implementation of routines for decoding and encoding
XML-RPC messages is used. This implementation uses a full XML parser and should be able to handle
anything XML dictates.
In general, when only small amounts of data is being passed back and forth, most of the cost of a remote
procedure call is actually consumed in the costs of starting up and ripping down the TCP/IP connection
by the client and of the server responding to the connection request. That the XML-RPC encoding and
decoding routines are implemented in Python may not therefore have any significant impact. However,
when large amounts of data are being passed around, this may not be the case.
An alternative to the Python implementation is one implemented in C++. This implementation will be
quicker at decoding XML-RPC messages, but does not use a full XML parser and thus will not work
if XML constructs such as comments and CDATA are used. The implementation also may not always
handle out of order elements in the method call and struct elements. The C++ implementation if desired
can be selected by supplying a keyword argument when initialising the XML-RPC gateway.
# Default uses Python implementation.
rpcgw1 = netsvc.xmlrpc.RpcGateway(group)
# Use C++ implementation instead.
rpcgw2 = netsvc.xmlrpc.RpcGateway(group,variant="c++")