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

旧时模样 提交于 2019-12-04 03:33:41

问题


I'm creating web services in python using Spyne based on this example. However, all my services are combined into one wsdl file locating at http://localhost:8000/?wsdl. I'm looking for another way to deploy each web service separately in a single wsdl file, e.g. http://localhost:8000/service1/?wsdl and http://localhost:8000/service2?wsdl


回答1:


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.



来源:https://stackoverflow.com/questions/20275836/deploy-multiple-web-services-i-e-multiple-wsdl-files-in-python

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