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.