0

Spyne+Twisted で Python SOAP サーバーを実装しようとしています。

これがサンプルサーバーコードです

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

さて、私は何をすべきですか?前もって感謝します

更新: ?wsdl(小文字に注意してください) を参照した後、405 エラーはなくなりましたが、これはその後の結果です:

エラー

4

2 に答える 2

0

?wsdlビットは大文字と小文字を区別します。

http://localhost:8000/?wsdl動作するはずです。

「 を参照する」とは、「http://localhost:8000/に GET リクエストを発行すること」を意味し、http://localhost:8000/SOAP over HTTP を実行する場合は禁止されています。SOAP エンドポイントは POST リクエストのみを受け入れるため、405.

于 2014-02-15T21:10:45.503 に答える
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')
于 2016-10-07T03:24:07.040 に答える