在python中部署多个Web服务,即多个wsdl文件 [英] Deploy multiple web services, i.e. multiple wsdl files, in python
问题描述
我正在基于此示例,使用Spyne在python中创建Web服务. .但是,我所有的服务都组合到一个位于http://localhost:8000/?wsdl
的wsdl文件中.我正在寻找另一种在单个wsdl文件中分别部署每个Web服务的方法,例如
http://localhost:8000/service1/?wsdl
和http://localhost:8000/service2?wsdl
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
推荐答案
Spyne为此提供了一个WsgiMounter
类:
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,
})
现在,您可以使用与传递WsgiApplication
实例相同的方式,将wsgi_app
传递给Wsgi实现.
Now you can pass wsgi_app
to the Wsgi implementation that you're using the same way you'd pass a WsgiApplication
instance.
您的Wsgi实现也肯定具有类似的功能,您也可以在例如您需要为根请求提供服务,而不是为空的404请求提供服务.
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
请注意,您不能将一个Service
类用于多个应用程序.如果必须这样做,可以这样:
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
,并对每个Application
实例使用SomeServiceFactory()
调用.
and use the SomeServiceFactory()
call for every Application
instance.
例如
app1 = Application([SomeServiceFactory()], tns=tns,
in_protocol=Soap11(), out_protocol=Soap11())
app2 = Application([SomeServiceFactory()], tns=tns,
in_protocol=Soap11(), out_protocol=Soap11())
希望有帮助.
这篇关于在python中部署多个Web服务,即多个wsdl文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!