An issue with the soaplib hello world program

2.5k views Asked by At

I am trying to get this server to run however I keep getting an error:

server:

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

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)
        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"

error:

Traceback (most recent call last):
  File "C:/Users/User/Desktop/wsdlHelloWorld.py", line 8, in <module>
    class HelloWorldService(DefinitionBase):
  File "C:/Users/User/Desktop/wsdlHelloWorld.py", line 9, in HelloWorldService
    @soap(String,Integer,_returns=Array(String))
NameError: name 'soap' is not defined

This is where I found it so I would assume something is wrong on my end, I had tried to install soaplib a few times before and botched them up because of lxml relying on vcvarsall.bat, however I shouldn't think that would matter...

Update

well I got the example to work by adding soap to my soaplib.core.service imports (duh). So...

from soaplib.core.service import rpc, DefinitionBase, soap

however now when I try and use the suds client example they provide I get this error.

  File "C:\Python27\lib\urllib2.py", line 1174, in do_open
    raise URLError(err)
URLError: <urlopen error [Errno 10061] No connection could be made because the target machine actively refused it>

Update

A nmap scan reveals that there is no service running on port 7789, which will cause urllib2 to throw a 10061 error.

2

There are 2 answers

0
securedome On BEST ANSWER

Add the following line to your imports

   from soaplib.core.service import soap

And it should work fine ;-)

securedome

1
DhruvPathak On

Shouldn't it be : @soapmethod(String,Integer,_returns=Array(String)) ?