Remote Access

port = 8000

group = "web-services"

httpd = netsvc.HttpDaemon(port)

rpcgw = netsvc.soap.RpcGateway(group) httpd.attach("/service",rpcgw) httpd.start()

dispatcher.run()

To complement the SOAP gateway, a SOAP client is provided in the "netrpc.soap" module. This client is only suitable for use against SOAP based web services which rely on positional arguments. Most web services use WSDL and therefore require named parameters, making the client unsuitable in those cases.

import netrpc.soap

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

If using this client against a SOAP server written using a different system, it may be necessary to bind the method call to a specific namespace and/or provide a specific value for the "SOAPAction" header of the SOAP request. If this is the case, a method namespace can be supplied using the "ns" keyword argument when creating the instance of the RemoteService class. Similarly, a value for the "SOA- PAction" header can be supplied using the "soapaction" keyword argument. If no "soapac- tion" argument is supplied, the value of the "SOAPAction" header will be a pair of double quotes.

url = "http://services.soaplite.com/hibye.cgi" uri = "http://www.soaplite.com/Demo"

service = netrpc.soap.RemoteService(url,ns=uri) print service.hi()

If a particular SOAP server requires a different method namespace or "SOAPAction" header for each method called, the "ns" and "soapaction" keyword arguments can instead be supplied at the point the call is made, rather than when the RemoteService object is created.

Note that although SOAP is type extendable, because the namespace associated with a new type name must be bound to a URI, the lesser described type information used by the service agent framework can’t be transparently translated into valid XML as per the SOAP encoding rules. You are therefore limited to types described by the XML Schema Datatypes specification, although at present not all such types may be translated by the SOAP gateway. In the future as experience and demand dictates, the gateway will be amended however to ensure that any types from the XML Schema Datatypes are passed through appropriately.

In respect of a failure response generated by the service agent framework, the four fields will be en- coded as separate fields within the SOAP fault structure detail element enclosed with an XML element

122

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