url='http://api.google.com/GoogleSearch.wsdl'

from ZSI.ServiceProxy import ServiceProxy as sp
s=sp(url)

#To Enable traceback uncomment below
#import sys
#s=sp(url,tracefile=sys.stdout)

dir(s)
#Above will print a list the methods, and other functions you have available

#Below will print available methods and their names:

from ZSI.schema import GED
print s._methods.keys()
for x in s._methods.keys():
        for i in s._methods[x][0].callinfo.inparams:
                print 'Inparameters',i.name,i.type,GED(*i.type)
        for i in s._methods[x][0].callinfo.outparams:
                print 'outparameters',i.name,i.type,GED(*i.type)

Read in xml

import xml.dom.minidom
xmlfile=xml.dom.minidom.parse("Example1.xml")
file1=xmlfile.toxml()

import xml.dom.minidom
xmlfile=xml.dom.minidom.parse("Example1.xml")
file1=xmlfile.toxml()

response=s.Submit(_User='myusername',_Password='mypassword',_xmlData=file1)
print response

#Response will be a dictionary so in order to get the xml you need to know the name of the return function.

responsefile=xml.dom.minidom.parseString(response['_SubmitResult'])
f=open('ResponseFile.xml','w')
f.write(responsefile.toprettyxml())
f.close()

wsdl2py

wsdl2py --complexType "http://api.google.com/GoogleSearch.wsdl"

Troubleshoot

Communication traceback

from ZSI import ServiceProxy
url='http://api.google.com/GoogleSearch.wsdl'

import sys
s=sp(url,tracefile=sys.stdout)

from ZSI import ServiceProxy
url='http://api.google.com/GoogleSearch.wsdl'

fp=open('soap.log','a')
s=sp(url,tracefile=fp)

fp.close() 

TypeError: Not supporting SOAPENC:Arrays or XSD:List

TypeError: Not supporting SOAPENC:Arrays or XSD:List 

Seems I have to pass the arguments to the methods as named arguments, like
so:

value = service.basic_call(_username="somestring",
_password="anotherstring") 

References

http://www.ebi.ac.uk/Tools/webservices/tutorials/06_programming/python/soap/zsi

MyWiki: SOAP (last edited 2012-08-27 15:04:06 by LukaszSzybalski)