1

我正在尝试使用 Spyne 创建一个 SOAP Web 服务。基于简单的Hello 示例,我想创建 2 个不同的服务:

from spyne.application import Application
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication

from spyne.decorator import rpc
from spyne.service import ServiceBase
from spyne.model.complex import Iterable
from spyne.model.primitive import Unicode

class HelloWorldService(ServiceBase):
    @rpc(Unicode, _returns=Iterable(Unicode))
    def say_hello(ctx, name):
        return [u'Hello, %s' % name]

class HelloWorldService1(ServiceBase):
    @rpc(Unicode, _returns=Iterable(Unicode))
    def say_hello1(ctx, name):
        return [u'Hello, %s' % name]

if __name__=='__main__':
    from wsgiref.simple_server import make_server

    application = Application([HelloWorldService, HelloWorldService1],
                'spyne.examples.hello.soap',
                in_protocol=Soap11(validator='lxml'),
                out_protocol=Soap11()
            )
    wsgi_application = WsgiApplication(application)

    server = make_server('127.0.0.1', 8000, wsgi_application)
    server.serve_forever()

但是,当我尝试使用 suds 使用这些服务时:

from suds.client import Client
client = Client('http://localhost:8000/?wsdl')
print client

只有一项服务可用:

Service ( HelloWorldService ) tns="spyne.examples.hello.soap"
   Prefixes (1)
      ns0 = "spyne.examples.hello.soap"
   Ports (1):
      (Application)
         Methods (1):
            say_hello(xs:string name, xs:integer times, )
         Types (3):
            say_hello
            say_helloResponse
            stringArray

所以,我想知道我是否错过了什么。此外,如果可能的话,谁能告诉我如何在 Spyne 中创建多个服务,每个服务都有自己的 wsdl 文件。

4

1 回答 1

2

您的代码是正确的,并且会同时显示 say_hello 和 say_hello1 方法。也许您应该在清除客户端的 wsdl 缓存后重试。

http://localhost:8000/?wsdl您可以通过在浏览器中访问来查看实际的 wsdl 文档。

于 2013-11-26T18:32:35.027 回答