[Tutor] Re: SOAP

dominic.fox dominic.fox" <dominic.fox@ntlworld.com
Sat, 6 Jul 2002 17:00:11 +0100


OK, now I have it working (thanks to Danny). The trouble was indeed with
SOAP.py 0.97, which is apparently incompatible with Python 2.2.1. I
installed the version included with pyGoogle and everything went swimmingly.

Now I thought it might be useful to delve a little beneath the surface of
pyGoogle's helpful proxy interface, just for the sake of understanding SOAP
a little better. What seems to be going on underneath the hood is that
SOAP.py is serialising Python data types into SOAP-conformant XML and back
again, returning the deserialised results (in this case the Google search
results) as a SOAP.structType object which pyGoogle then parses and formats
in a number of helpful ways. Here's what I tried:

>>> myGoogle = SOAP.SOAPProxy(
 "http://api.google.com/search/beta2",
 namespace="urn:GoogleSearch")

>>> retval = myGoogle.doGoogleSearch(myLicenceKey, "SOAP", 0, 10,
SOAP.booleanType(0), "", SOAP.booleanType(1), "", "latin1", "latin1")

Note that you have to convert Python's 1s and 0s into SOAP.booleanType
objects in order for them to be serialized properly.

>>> retval
<SOAP.structType return at 23747008>

>>> retval._asdict
{u'searchTips': '', u'endIndex': 10, u'searchQuery': 'SOAP',
u'searchComments': '', u'resultElements': [<SOAP.structType item at
23756992>, <SOAP.structType item at 23633424>, <SOAP.structType item at
23823584>, <SOAP.structType item at 23832816>, <SOAP.structType item at
23769744>, <SOAP.structType item at 23901872>, <SOAP.structType item at
23913936>, <SOAP.structType item at 23934128>, <SOAP.structType item at
23932752>, <SOAP.structType item at 23921056>], u'directoryCategories':
[<SOAP.structType item at 23776880>], u'estimatedTotalResultsCount':
3690000, u'estimateIsExact': 0, u'startIndex': 1, u'documentFiltering': 0,
u'searchTime': 0.068235000000000004}

- finally, borrowing from pyGoogle:

>>> results = [node._asdict for node in retval.resultElements]

which breaks the sub-structs inside the struct-as-dictionary into
structs-as-dictionaries which contain the actual search results.

It looks as if SOAP is good for returning rather larger and more complex
records or data structures than XML-RPC can handle, and also for specifying
and validating those structures using XML Schemas. The question has to be
whether (or when and where) the overheads involved are worth it. Obviously
once you've got a neat little library of proxies for the API you want to use
(like pyGoogle), this isn't so much of an issue; but that might mean having
a library per SOAP service, whereas xmlrpclib gives you a fairly
transparently Pythonic way of plugging into *anything*...

Dominic