Qualified element/attribute forms and unqualified forms with Spyne soap server
Asked Answered
V

2

7

Is there any way to use elementFormDefault="unqualified" server schema type with Spyne server? Now my all trials end up with method response result:

<senv:Envelope xmlns:tns="http://test.com/remoteService/"
xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">
<senv:Body>
    <tns:testResponse>
        <tns:status>ok</tns:status>
    </tns:testResponse>
</senv:Body>

And generated wsdl fragment with "qualified" elementFormDefault :

<xs:schema targetNamespace="http://test.com/remoteService/" elementFormDefault="qualified"></xs:schema>

How to configure method or parameters model to get result like this:

<senv:Envelope xmlns:tns="http://test.com/remoteService/"
xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">
<senv:Body>
    <tns:testResponse>
        <status>ok<status>
    </tns:testResponse>
</senv:Body>

My goal is to generate result where child element:

<tns:status>ok</tns:status>

will appear without namespace prefix - like this:

<status>ok<status>
Vassalize answered 7/5, 2013 at 13:14 Comment(0)
S
6

If you wonder how to add listener to the event_manager for method_return_string or for another event, see bellow a full example:

from spyne import Application, rpc, ServiceBase, Iterable, Integer, Unicode

from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication


class HelloWorldService(ServiceBase):
    @rpc(Unicode, Integer, _returns=Iterable(Unicode))
    def say_hello(ctx, name, times):
        for i in range(times):
            yield u'Hello, %s' % name


def on_method_return_string(ctx):
    ctx.out_string[0] = ctx.out_string[0].replace(b'Hello>', b'Good by')

HelloWorldService.event_manager.add_listener('method_return_string', 
                                              on_method_return_string)

application = Application([HelloWorldService], 'spyne.examples.hello.soap',
                          in_protocol=Soap11(validator='lxml'),
                          out_protocol=Soap11())

wsgi_application = WsgiApplication(application)


if __name__ == '__main__':
    import logging

    from wsgiref.simple_server import make_server
    server = make_server('127.0.0.1', 8000, wsgi_application)
    server.serve_forever()

As of Spyne 2.12 this is still the only way to remove namespaces from response variables.

Sophia answered 13/10, 2016 at 16:2 Comment(0)
G
1

As of 2.10, Spyne does not support this.

The patch would be a bit hairy. Chime in at [email protected] if you're willing to work on this.

A workaround would be to remove namespace prefixes manually from outgoing documents in a method_return_document hook. If you need to enforce the same for incoming documents as well, you either have to modify the Wsdl as well in a document_built event, or use soft validation (soft validation does not care about namespaces) or no validation at all.

Gride answered 8/5, 2013 at 12:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.