Remote Access

# Explicitly specify use of Python implementation.

rpcgw3 = netsvc.xmlrpc.RpcGateway(group,variant="python")

Both these Python and C++ implementations of the routines for handling the XML-RPC protocol are supplied with OSE. Because of the limitations of the XML-RPC protocol in respect of passing a more diverse set of types, when these implementations are used, types which don’t have a direct equivalent in XML-RPC will have their encoded value passed as a string, with a subsequent loss of type informa- tion.

For example, the Python None type will be sent as an empty string. Note this only applies to the result of a request when it is being returned via an XML-RPC request. Since XML-RPC doesn’t support the extra types, a client strictly conforming to the XML-RPC protocol would not have been able to gener- ate them in the first place.

Although there are numerous third party XML-RPC clients available, including a number for Python, an XML-RPC client is also provided with OSE. This client is interface compatible with that provided by the "netrpc" module and is available in the "netrpc.xmlrpc" module. This provides exactly the same interface as the "netrpc" module, even to the extent of being able to reconstruct the more informative failure responses provided by the service agent framework.

import netrpc.xmlrpc

url = "http://localhost:8000/service/validator" service = netrpc.xmlrpc.RemoteService(url) print service.echo(1,1L,1.1,"1")

What happens when a failure occurs is that the additional information provided by the service agent framework is encoded into the description field of an XML-RPC fault. When this is received by the "xmlrpc" module it extracts out the information into separate fields once more. If you are using a third party XML-RPC client this will not occur. What you will find instead is that the fault code will equate to the error code of a failure, with the description included with the fault looking something like the following.

origin -- the description

additional fault details

That is, the description is prefixed by the origin of the failure, separated by "--". The additional details of the failure will then appear separated from the description by a blank line. You could either use this as is, or separate out the information yourself.

Note that when using the "xmlrpc" module the encoders and decoders become largely irrelevant giv- en that the XML-RPC protocol is not type extendable. Although the "xmlrpc" module provides an interface compatible with the "netrpc" module, it still may be used to make requests against third party XML-RPC servers.

120

Page 120
Image 120
Python Python Manual, 7.0pl5 manual 120