Python soap using soaplib (server) and suds (client)

Posted by Celso Axelrud on Stack Overflow See other posts from Stack Overflow or by Celso Axelrud
Published on 2010-01-02T17:51:55Z Indexed on 2010/05/06 12:18 UTC
Read the original article Hit count: 1266

Filed under:
|
|

This question is related to: http://stackoverflow.com/questions/1751027/python-soap-server-client

In the case of soap with python, there are recommendation to use soaplib (http://wiki.github.com/jkp/soaplib) as soap server and suds (https://fedorahosted.org/suds/) as soap client. My target is to create soap services in python that can be consumed by several clients (java, etc). I tried the HelloWorld example from soaplib (http://trac.optio.webfactional.com/wiki/HelloWorld). It works well when the client is also using soaplib.

Then, I tried to use suds as client consuming the HelloWorld services and it fail. -Why this is happening? Does soaplib server has problems to consumed by different clients?

Here the code for the server:

from soaplib.wsgi_soap import SimpleWSGISoapApp
from soaplib.service import soapmethod
from soaplib.serializers.primitive import String, Integer, Arraycode
class HelloWorldService(SimpleWSGISoapApp):
@soapmethod(String,Integer,_returns=Array(String))
def say_hello(self,name,times):
    results = []
    for i in range(0,times):
        results.append('Hello, %s'%name)
    return results

if __name__=='__main__':
from cherrypy.wsgiserver import CherryPyWSGIServer
#from cherrypy._cpwsgiserver import CherryPyWSGIServer
# this example uses CherryPy2.2, use cherrypy.wsgiserver.CherryPyWSGIServer for CherryPy 3.0
server = CherryPyWSGIServer(('localhost',7789),HelloWorldService())
server.start()

This is the soaplib client:

from soaplib.client import make_service_client
from SoapServerTest_1 import HelloWorldService
client = make_service_client('http://localhost:7789/',HelloWorldService())
print client.say_hello("Dave",5)

Results:

>>> ['Hello, Dave', 'Hello, Dave', 'Hello, Dave', 'Hello, Dave', 'Hello, Dave']

This is the suds client:

from suds.client import Client
url = 'http://localhost:7789/HelloWordService?wsdl'
client1 = Client(url)
client1.service.say_hello("Dave",5)

Results:

    >>> Unhandled exception while debugging...
Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\RTEP\Sequencing\SoapClientTest_1.py", line 10, in <module>
    client1.service.say_hello("Dave",5)
  File "c:\python25\lib\site-packages\suds\client.py", line 537, in __call__
    return client.invoke(args, kwargs)
  File "c:\python25\lib\site-packages\suds\client.py", line 597, in invoke
    result = self.send(msg)
  File "c:\python25\lib\site-packages\suds\client.py", line 626, in send
    result = self.succeeded(binding, reply.message)
  File "c:\python25\lib\site-packages\suds\client.py", line 658, in succeeded
    r, p = binding.get_reply(self.method, reply)
  File "c:\python25\lib\site-packages\suds\bindings\binding.py", line 158, in get_reply
    result = unmarshaller.process(nodes[0], resolved)
  File "c:\python25\lib\site-packages\suds\umx\typed.py", line 66, in process
    return Core.process(self, content)
  File "c:\python25\lib\site-packages\suds\umx\core.py", line 48, in process
    return self.append(content)
  File "c:\python25\lib\site-packages\suds\umx\core.py", line 63, in append
    self.append_children(content)
  File "c:\python25\lib\site-packages\suds\umx\core.py", line 140, in append_children
    cval = self.append(cont)
  File "c:\python25\lib\site-packages\suds\umx\core.py", line 61, in append
    self.start(content)
  File "c:\python25\lib\site-packages\suds\umx\typed.py", line 77, in start
    found = self.resolver.find(content.node)
  File "c:\python25\lib\site-packages\suds\resolver.py", line 341, in find
    frame = Frame(result, resolved=known, ancestry=ancestry)
  File "c:\python25\lib\site-packages\suds\resolver.py", line 473, in __init__
    resolved = type.resolve()
  File "c:\python25\lib\site-packages\suds\xsd\sxbasic.py", line 63, in resolve
    raise TypeNotFound(qref)
TypeNotFound: Type not found: '(string, HelloWorldService.HelloWorldService, )'

© Stack Overflow or respective owner

Related posts about soap

Related posts about python