0

I am trying to implement a python SOAP server with Spyne+Twisted.

Here is the sample server code

import logging
logging.basicConfig(level=logging.DEBUG)
from spyne.application import Application
from spyne.decorator import srpc
from spyne.service import ServiceBase
from spyne.model.primitive import Integer
from spyne.model.primitive import Unicode
from spyne.model.complex import Iterable
from spyne.protocol.soap import Soap11
from spyne.server.twisted import TwistedWebResource
from twisted.internet import reactor
from twisted.web.server import Site


class HelloWorldService(ServiceBase):
    @srpc(Unicode, Integer, _returns=Iterable(Unicode))
    def say_hello(name, times):
        for i in range(times):
            yield 'Hello, %s' % name


application = Application([HelloWorldService],
                          tns='spyne.examples.hello',
                          in_protocol=Soap11(),
                          out_protocol=Soap11()
                          )

if __name__ == '__main__':
    resource = TwistedWebResource(application)
    site = Site(resource)
    reactor.listenTCP(8000, site, interface='0.0.0.0')
    reactor.run()

Pretty simple.

Here is client code:

from pysimplesoap.client import SoapClient
import sys

if __name__ == '__main__':
    client = SoapClient(wsdl="http://{0}:{1}/?WSDL".format(sys.argv[1], sys.argv[2]))
    response = client.add_job('black')
    print 'result is ', response['add_jobResult']

and I run client with python client.py localhost 8000

Here is what client gives me:

No handlers could be found for logger "pysimplesoap.simplexml"
Traceback (most recent call last):
  File "client.py", line 22, in <module>
    client = SoapClient(wsdl="http://{0}:{1}/?WSDL".format(sys.argv[1], sys.argv[2]))
  File "/usr/local/lib/python2.7/dist-packages/PySimpleSOAP-1.10-py2.7.egg/pysimplesoap/client.py", line 133, in __init__
    self.services = wsdl and self.wsdl_parse(wsdl, cache=cache)
  File "/usr/local/lib/python2.7/dist-packages/PySimpleSOAP-1.10-py2.7.egg/pysimplesoap/client.py", line 471, in wsdl_parse
    wsdl = SimpleXMLElement(xml, namespace=wsdl_uri)
  File "/usr/local/lib/python2.7/dist-packages/PySimpleSOAP-1.10-py2.7.egg/pysimplesoap/simplexml.py", line 196, in __init__
    self.__document = xml.dom.minidom.parseString(text)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 1931, in parseString
    return expatbuilder.parseString(string)
  File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 940, in parseString
    return builder.parseString(string)
  File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
xml.parsers.expat.ExpatError: syntax error: line 1, column 0

Also, browsing to http://localhost:8000/?WSDL gives this:

405 Method Not Allowed

Now, what should I do? Thanks in advance

UPDATE: after browsing to ?wsdl (notice lower case) 405 error is gone, but this is what I get after that:

Error

vfsoraki
  • 2,186
  • 1
  • 20
  • 45

2 Answers2

0

The ?wsdl bit is case sensitive.

http://localhost:8000/?wsdl should work.

"Browsing to http://localhost:8000/" means "issuing a GET request to http://localhost:8000/" which is forbidden when doing SOAP over HTTP -- SOAP endpoints only accept POST requests, hence the 405.

Burak Arslan
  • 7,671
  • 2
  • 15
  • 24
0

this may be soaplib bug ;

I also met the issue : http://localhost:8000/?wsdl is ok http://localhost:8000/?WSDL will be 405 error

I modify my soaplib wsgi.py to fix the issue (/usr/local/lib/python2.7/dist-packages/soaplib-2.0.0b2-py2.7.egg/soaplib/core/server/wsgi.py)

modified content as following:

req_env['QUERY_STRING'].endswith('wsdl') or req_env['PATH_INFO'].endswith('wsdl')  or req_env['QUERY_STRING'].endswith('WSDL') or req_env['PATH_INFO'].endswith('WSDL')
Miuranga
  • 2,463
  • 10
  • 51
  • 81