2014-02-15 48 views
0

我想用Spyne + Twisted實現一個python SOAP服務器。Spyne +扭曲的SOAP服務器給出了405錯誤

下面是示例服務器代碼

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

相當簡單。

下面是客戶端代碼:

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'] 

和我運行客戶端python client.py localhost 8000

下面是客戶給我:

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 

而且,瀏覽到http://localhost:8000/?WSDL給出了這樣的:

405 Method Not Allowed 

現在,我該怎麼辦? 在此先感謝

UPDATE:

Error

+0

即使瀏覽到「http:// localhost:8000 /」也會出現405 – vfsoraki

+0

btw,爲什麼不使用泡沫? –

+0

對不起,用什麼? – vfsoraki

回答

0

?wsdl位是區分大小寫的: 瀏覽到?wsdl(注意小寫)405錯誤消失,但這是我之後得到了。

http://localhost:8000/?wsdl應該工作。

「瀏覽到http://localhost:8000/」裝置「發出GET請求http://localhost:8000/」通過HTTP做SOAP時被禁止 - SOAP端點只接受POST請求,因此405

+0

謝謝!它工作,但發生了另一個錯誤。我更新了它的問題。 – vfsoraki

+0

堅持,這是一個錯誤。 –

+0

好的,我剛剛發佈了應該解決這個問題的2.10.10。請確認。 –

0

這可能是錯誤soaplib;

我也遇到了這個問題: http://localhost:8000/?wsdl是確定 http://localhost:8000/?WSDL將是405錯誤

修改我soaplib wsgi.py來解決該問題(/usr/local/lib/python2.7/dist-packages/soaplib-2.0.0b2-py2.7.egg/soaplib/core/server/wsgi.py)

修改內容如下:

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