0

I'm attempting to run the soaplib Hello World program:

import soaplib
from soaplib.core.service import rpc, DefinitionBase
from soaplib.core.model.primitive import String, Integer
from soaplib.core.server import wsgi
from soaplib.core.model.clazz import Array
from soaplib.core.service import soap


class HelloWorldService(DefinitionBase):
    @soap(String,Integer,_returns=Array(String))
    def say_hello(self,name,times):
        results = []
        for i in range(0,times):
            results.append('Hello, %s'%name)
        import pdb; pdb.set_trace() 
        return results

if __name__=='__main__':
    try:
        from wsgiref.simple_server import make_server
        soap_application = soaplib.core.Application([HelloWorldService], 'tns')
        wsgi_application = wsgi.Application(soap_application)
        server = make_server('localhost', 7789, wsgi_application)
        server.serve_forever()
    except ImportError:
        print "Error: example server code requires Python >= 2.5"

I was having problems connecting to the service, both using a browser and a simple suds client. I used the code from the top answer here to get a list of the methods of my little webservice, as well as they're parameters and types. The result I got wasn't particularly encouraging:

say_hello(None: say_hello)

So it appears that the reason that I was unable to call the function properly is that it's parameters and types do not appear to register: However, as far as I can tell this should not be the case. I'm particularly dumbfounded as this is the hello world program presented on the soaplib website.

I've searched both here and elsewhere, but I don't seem to find a similar problem anywhere. Any thoughts?

Community
  • 1
  • 1
user1401321
  • 111
  • 12

1 Answers1

1

I've tried the soaplib "Hello world" example. It works if you add from soaplib.core.service import soap as you did.

I've installed both soaplib and suds using pip install.

$ pip freeze | grep -e'soaplib\|suds'
soaplib==2.0.0-beta2
suds==0.4

It seems soaplib was refactored to rpclib which was replaced by spyne. It doesn't provide confidence in the project.

jfs
  • 399,953
  • 195
  • 994
  • 1,670
  • Indeed, you're right. Do you have any other suggestions for a toolkit for a python-based webservice? – user1401321 Jul 20 '12 at 13:59
  • A general suggestion would be don't use SOAP unless you have specific requirements that justify it. There are tons of [web-frameworks](http://wiki.python.org/moin/WebFrameworks). For a simple service you could start with something like Flask, Pyramid (suitable for RESTful services). `spyne` *might* be the best there is for SOAP-based services (I haven't evaluated SOAP options in a while). – jfs Jul 20 '12 at 14:35
  • Haha, believe me, I'd rather not use SOAP. Sadly, it's one of the requirements of the project I'm working on. :) Thanks for your suggestions! – user1401321 Jul 20 '12 at 14:43