2

Spyneフレームワークとコードのこの例の部分を使用して、python3でSOAPサービスをホストしようとしています:

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__':
    # You can use any Wsgi server. Here, we chose
    # Python's built-in wsgi server but you're not
    # supposed to use it in production.
    from wsgiref.simple_server import make_server
    wsgi_app = WsgiApplication(application)
    server = make_server('0.0.0.0', 8000, wsgi_app)
    server.serve_forever()

機能していますが、使用する名前空間は 1 つだけです。

tns='spyne.examples.hello'

この行で複数のサービスを定義できます。

application = Application([HelloWorldService, OtherService1, OtherService2]

しかし、サービスごとに異なる名前空間を定義することは可能ですか? このようなものは機能しません:

tns=['spyne.examples.hello', 'http://other.service1', 'http://other.service2']
4

1 に答える 1

4

WsgiMounterこれにはクラスを使用できます。

from spyne.util.wsgi_wrapper import WsgiMounter

app1 = Application([SomeService], tns=namespace1,
    in_protocol=Soap11(), out_protocol=Soap11())
app2 = Application([SomeOtherService], tns=namespace2,
    in_protocol=Soap11(), out_protocol=Soap11())
wsgi_mounter = WsgiMounter({
    'app1': app1,
    'app2': app2,
})

次に、wsgi_mounterコードで wsgi_app の代わりにオブジェクトを渡します。

if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    wsgi_mounter = WsgiMounter({
        'app1': app1,
        'app2': app2, 
    })
    server = make_server('0.0.0.0', 8000, wsgi_mounter)
    server.serve_forever()
于 2016-05-27T07:46:02.873 に答える