【问题标题】:Qualified element/attribute forms and unqualified forms with Spyne soap serverSpyne 肥皂服务器的合格元素/属性表格和不合格表格
【发布时间】:2013-05-07 13:14:18
【问题描述】:

有没有办法在 Spyne 服务器上使用 elementFormDefault="unqualified" 服务器模式类型? 现在我的所有试验都以方法响应结果结束:

<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>

并生成带有“合格” elementFormDefault 的 wsdl 片段:

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

如何配置方法或参数模型以获得这样的结果:

<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>

我的目标是生成子元素的结果:

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

将出现没有命名空间前缀 - 像这样:

<status>ok<status>

【问题讨论】:

    标签: soap python-2.7 spyne


    【解决方案1】:

    如果您想知道如何为 method_return_string 或其他事件添加侦听器到 event_manager,请参阅下面的完整示例:

    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()
    

    从 Spyne 2.12 开始,这仍然是从响应变量中删除命名空间的唯一方法。

    【讨论】:

      【解决方案2】:

      从 2.10 开始,Spyne 不支持此功能。

      补丁会有点毛茸茸的。如果您愿意为此工作,请在soap@python.org 加入。

      一种解决方法是从method_return_document 挂钩中的传出文档中手动删除命名空间前缀。如果您也需要对传入的文档强制执行相同的操作,您要么必须在 document_built 事件中修改 Wsdl,要么使用软验证(软验证不关心命名空间)或根本不进行验证。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-09-19
        • 2018-03-21
        • 2020-09-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多