从Spyne响应变量中删除名称空间 [英] Remove the namespace from Spyne response variables
问题描述
根据特定的WSDL实施WebService.客户端无法更改.正确处理了来自客户端的请求,但是由于变量中的名称空间,客户端抱怨响应.
Implementing a WebService according to a specific WSDL. Client cannot be changed. Correctly processing request from Client, but Client is complaining on Response because of namespace in variables.
我想要什么(基于WSDL的soapUI响应):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://callback.foo.com/">
<soapenv:Header/>
<soapenv:Body>
<cal:foo_statusResponse>
<result>SUCCESS</result>
<notify>Thanks!</notify>
</cal:foo_statusResponse>
</soapenv:Body>
</soapenv:Envelope>
我得到了什么(关于引起验证问题的变量的注意事项tns:
):
What I am getting (notice tns:
on variables causing validation issues):
<senv:Envelope xmlns:tns="http://callback.foo.com/" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">
<senv:Body>
<tns:foo_statusResponse>
<tns:result>SUCCESS</tns:result>
<tns:notify>Thanks!</tns:notify>
</tns:foo_statusResponse>
</senv:Body>
</senv:Envelope>
Java客户端抛出此异常:
[com.sun.istack.SAXParseException2; lineNumber:2; columnNumber:162; 意外元素(uri:" http://callback.foo.com/",本地:结果") . 期望的元素是< {} result>,< {} notify>]
[com.sun.istack.SAXParseException2; lineNumber: 2; columnNumber: 162; unexpected element (uri:"http://callback.foo.com/", local:"result"). Expected elements are <{}result>,<{}notify>]
实施摘要:
class fooStatusRS(ComplexModel):
result = Unicode()
notify = Unicode()
class foo_callback(ServiceBase):
@srpc(Unicode, Unicode, Unicode, Unicode, statusbarInfo, anotherResponse,
_out_header=None,
_out_variable_names=("result", "notify"),
_returns=(Unicode, Unicode),
_out_message_name="foo_statusResponse",
_operation_name="foo_status_rq")
def foo_status(foo_id, reply, ref, status, statusbar, another):
if foo_id:
print foo_id
return fooStatusRS(result="SUCCESS", notify="Foo received!")
推荐答案
This is not possible (yet) and is answered in a similar question here by the maintainer.
解决方法是将侦听器添加到"method_return_string"的event_manager中,然后执行一些字符串操作.
The work around was to add listener to the event_manager for "method_return_string" and then perform some string operations.
def _method_return_string(ctx):
ctx.out_string[0] = ctx.out_string[0].replace("tns:result>", "result>")
ctx.out_string[0] = ctx.out_string[0].replace("tns:notify>", "notify>")
这篇关于从Spyne响应变量中删除名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!