spyne icon indicating copy to clipboard operation
spyne copied to clipboard

Multiple namespace for diffrent services

Open ghost opened this issue 9 years ago • 3 comments

I'm trying to host SOAP service using this example part of code:

HelloWorldService(ServiceBase):
    @srpc(Unicode, Integer, _returns=Iterable(Unicode))
    def say_hello(name, times):
        for i in range(times):
            yield 'Hello, %s' % name
application = Application([HelloWorldService],
    tns='spyne.examples.hello',
    in_protocol=Soap11(),
    out_protocol=Soap11()
)
if __name__ == '__main__':
    # You can use any Wsgi server. Here, we chose
    # Python's built-in wsgi server but you're not
    # supposed to use it in production.
    from wsgiref.simple_server import make_server
    wsgi_app = WsgiApplication(application)
    server = make_server('0.0.0.0', 8000, wsgi_app)
    server.serve_forever()

It's working but it uses only one namespace. tns='spyne.examples.hello'

I can define multiple services in this line:

application = Application([HelloWorldService, OtherService1, OtherService2]

But is it possible to define diffrent namespace for each service? Something like this doesn't work:

tns=['spyne.examples.hello', 'http://other.service1', 'http://other.service2']

ghost avatar May 24 '16 17:05 ghost

Please follow up with the WSDL output you're after

plq avatar Jun 21 '16 15:06 plq

Currently in spyne you can't do this. You could solve this problem by defining multiple endpoints, so each application has it's own namespace:

from wsgiref.simple_server import make_server

from spyne import Application
from spyne.protocol.soap.soap11 import Soap11
from spyne.util.wsgi_wrapper import WsgiMounter

cow_application = Application(
    [CowService],
    tns='spyne.namespace.cow',
    name='cow',
    in_protocol=Soap11(validator='lxml'),
    out_protocol=Soap11()
)

chicken_application = Application(
    [ChickenService],
    tns='spyne.namespace.chicken',
    name='chicken',
    in_protocol=Soap11(validator='lxml'),
    out_protocol=Soap11()
)


wsgi_mounter = WsgiMounter({
    'cow': cow_application,
    'chicken': chicken_application,
})

server = make_server('0.0.0.0', 8000, wsgi_mounter)
server.serve_forever()

maerteijn avatar Feb 02 '17 19:02 maerteijn

How do I remove the namespace of parameters in an application? for example:tns:name =>

yunmo555 avatar Aug 07 '20 03:08 yunmo555