Benefits Of Twisted-suds - Async Way Of Using Python Suds Soap Lib
I'm using python suds library to make a SOAP client based on a local wsdl file. My goal is to use Twisted as the backend so I query the SOAP servers in a asyncronous way. I know th
Solution 1:
I'm using suds in my projects. I didn't have to do any patches, or use twisted-suds. I'm using the 0.4.1-2 version of python-suds package (on ubuntu) and it comes with very usefull nosend option.
# This parses the wsdl file. The autoblend option you'd probably skip,
# its needed when name spaces are not strictly preserved (case for Echo Sign).
from suds import client
self._suds = client.Client('file://' + config.wsdl_path, nosend=True,
autoblend=True)
....
# Create a context for the call, example sendDocument() call. This doesn't yet
# send anything, only creates an object with the request and capable of parsing
# the response
context = self._suds.service.sendDocument(apiKey=....)
# Actually send the request. Use any web client you want. I actually use
# something more sophisticated, but below I put the example using
# standard twisted web client.
from twisted.web import client
d = client.getPage(url=context.client.location(),
postdata=str(context.envelope),
method='POST',
headers=context.client.headers())
# The callback() of the above Deferred is fired with the body of the
# http response. I parse it using the context object.
d.addCallback(context.succeeded)
# Now in the callback you have the actual python object defined in
# your WSDL file. You can print...
from pprint import pprint
d.addCallback(pprint)
# I the response is a failure, your Deferred would be errbacked with
# the suds.WebFault exception.
Post a Comment for "Benefits Of Twisted-suds - Async Way Of Using Python Suds Soap Lib"