Deploy multiple web services, i.e. multiple wsdl files, in python

老子叫甜甜 提交于 2019-12-01 18:49:24

Spyne has a WsgiMounter class for this:

from spyne.util.wsgi_wrapper import WsgiMounter

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

Now you can pass wsgi_app to the Wsgi implementation that you're using the same way you'd pass a WsgiApplication instance.

Your Wsgi implementation also would definitely have a similar functionality, you can also use that in case e.g. you need to serve something for the root request instead of an empty 404 request.

An up-to-date fully working example can be found at: https://github.com/plq/spyne/blob/master/examples/multiple_protocols/server.py

Please note that you can't use one Service class with multiple applications. If you must do that, you can do it like this:

def SomeServiceFactory():
    class SomeService(ServiceBase):
        @rpc(Unicode, _returns=Unicode)
        def echo_string(ctx, string):
            return string
    return SomeService

and use the SomeServiceFactory() call for every Application instance.

e.g.

app1 = Application([SomeServiceFactory()], tns=tns,
        in_protocol=Soap11(), out_protocol=Soap11())
app2 = Application([SomeServiceFactory()], tns=tns,
        in_protocol=Soap11(), out_protocol=Soap11())

Hope that helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!