The SOAP Gateway

The SOAP Gateway

Yet another alternative to XML-RPC is the SOAP protocol. A starting point for SOAP is the site "http:/ /www.develop.com/soap". Although SOAP is newer than XML-RPC and is notionally type extenda- ble, it actually has some more significant limitations than XML-RPC. As with XML-RPC, it is only recommended that you use this protocol in preference to the NET-RPC protocol if you really have to. In doing so you will need to write your code keeping in mind these limitations.

The biggest limitation of the SOAP protocol at present is that the specification uses XML element names to describe the member keys in structures. At present, using the default SOAP encoding such structures are the only way of representing a Python dictionary. The service agent framework already restricts keys in dictionaries to strings, but the SOAP protocol limits what values those keys can have because of the XML naming rules.

More specifically, XML says that an element name, and thus a key in a Python dictionary, cannot start with a number. Further to this, a key would not be able to contain white space, a whole host of punc- tuation characters, nor would a key be able to start with the string "xml" in any mix of upper or lower case. It is also not possible to represent an empty dictionary in SOAP. These amount to being quite a severe restriction and effectively means that dictionaries need to be converted into a list of key/value tuples in order to be sent correctly.

The Apache SOAP toolkit has defined an alternative compound type which would be suitable for rep- resenting a dictionary, but only a few SOAP toolkits actually support it. It is also questionable as to whether a SOAP client would interchangeable accept this new type in any place where a structure may appear. Inevitably, Microsoft and IBM will come up with yet another scheme for doing the same thing, so any consensus is likely to be long in coming.

At present the default SOAP gateway relies on a third party "ZSI" module from the "pywebsvcs" toolkit. To use the SOAP gateway, you will need to have separately obtained this third party module from "http://sourceforge.net/projects/pywebsvcs" and installed it. You must have version 1.2 RC2 or later of this package. It is not possible to use version 1.1 or earlier of this package because of bugs in the package.

If you still wish to use the SOAP gateway, the only real change you would need to make to your code would be to instantiate an instance of the SOAP gateway in place of the NET-RPC gateway. Obviously though, if your service produces data which doesn’t fit within the limitations of the SOAP protocol the gateway will generate XML which a client will not be able to parse.

import netsvc import netsvc.soap

dispatcher = netsvc.Dispatcher() dispatcher.monitor(signal.SIGINT)

validator = Validator()

121

Page 121
Image 121
Python 7.0pl5, Python Manual manual Soap Gateway, 121