使用Spyne Soap Server的合格元素/属性表格和不合格表格 [英] Qualified element/attribute forms and unqualified forms with Spyne soap server
问题描述
是否可以在Spyne服务器上使用elementFormDefault ="unqualified"服务器模式类型? 现在,我所有的试验都以方法响应结果告终:
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>
并生成带有"qualified" elementFormDefault的wsdl片段:
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>
推荐答案
如果您想知道如何将监听器添加到method_return_string
或其他事件的event_manager中,请参见下面的完整示例:
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()
从Spyne 2.12开始,这仍然是从响应变量中删除名称空间的唯一方法.
As of Spyne 2.12 this is still the only way to remove namespaces from response variables.
这篇关于使用Spyne Soap Server的合格元素/属性表格和不合格表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!