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
Asked
Active
Viewed 974 times
4

Long Thai
- 807
- 3
- 12
- 34
1 Answers
6
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.

Burak Arslan
- 7,671
- 2
- 15
- 24
-
Please correct me if I'm wrong - does this allow multiple namespaces to be used in single Spyne service? – Asunez May 25 '16 at 10:08
-
thanks for the link to the working example! I was looking for that! – alcor Jun 26 '17 at 10:36