Using SOAPpy to Access SOAP Web Services Through a WSDL File
The dynamics of the Python language make it a perfect fit for SOAP web services. The SOAPpy module, available at http://pywebsvcs.sourceforge.net/, includes functions that enable you to create Python scripts that allow you to access SOAP web services. This phrase is designed to familiarize you with using the SOAPpy module to access SOAP web services through a Web Service Definition Language (WSDL) file. A WSDL file is an XML file that describes the URL, namespace, type of web service, functions, arguments, argument data types, and function return values of the SOAP web service. In this case, the sample code accesses the Google search SOAP web service through the GoogleSearch.wsdl file. The first step is to create an instance of the WSDL proxy server using the WSDL.Proxy(wsdlfile) function of the SOAPpy module. The WSDL.Proxy function accepts a WSDL filename as its only argument and returns a WSDL proxy server object. After you have created the WSDL proxy server object, you can view the available methods using the methods attribute of the WSDL proxy server object, as shown in the sample code wServer.methods.keys(). The methods attribute is a dictionary containing the available methods of the web service. To view the arguments associated with a specific method, look up the method in the dictionary to get a method data object, as shown in the sample code Server.methods['doGoogleSearch']. Once you have the method data object, the arguments can be accessed using the inparams attribute, which is a list of parameter objects. The name and type of the parameter are available using the name and type attributes of the parameter object, as shown in the sample code p.name.ljust(12), p.type[1]). The methods on the SOAP server can be called as methods of the WSDL proxy server object using the "." syntax as shown in the example soap_wsdl.py. Note This phrase focuses on using Google's SOAP web service; however, there are numerous services out there that can be accessed in much the same way. A good place to start is to look at the services provided at http://www.xmethods.net/. Note In the sample code, key is set to INSERT_YOUR_KEY_HERE. You will need to go to http://api.google.com and create an account to get your own key. Once you have your own key, insert it into the sample code. from SOAPpy import WSDL soap_wsdl.py Available Methods Output of soap_wsdl.py |
Tuesday, November 3, 2009
Using SOAPpy to Access SOAP Web Services Through a WSDL File
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment