spyne中不允许使用encodingStyle属性

0 投票
1 回答
631 浏览
提问于 2025-04-18 15:24

我正在尝试用spyne构建一个SOAP服务,以处理这样的请求:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:MyService">
<soapenv:Header/>
  <soapenv:Body>
    <urn:test_rpc soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <urn:in0>test</urn:in0>
    </urn:test_rpc>
  </soapenv:Body>
</soapenv:Envelope>

我的测试方法看起来是这样的:

@spyne.srpc(Unicode, _return=Result, _in_variable_names={"input": 'in0'}, _body_style='wrapped')
def test_rpc(input):
  return Result()

当我发送请求时,SOAP服务返回了以下的Webfault错误:

Server raised fault: ':1:0:ERROR:SCHEMASV:SCHEMAV_CVC_COMPLEX_TYPE_3_2_1: Element '{urn:MyService}test_rpc', attribute '{http://schemas.xmlsoap.org/soap/envelope/}encodingStyle': The attribute '{http://schemas.xmlsoap.org/soap/envelope/}encodingStyle' is not allowed.' 

我该如何解决这个问题,而不去删除encodingStyle这个设置呢?SOAP 1.1的W3C说明书第4.1.1节提到,“这个属性[encodingStyle]可以出现在任何元素上,...”

1 个回答

0

从2.11版本开始,Spyne不支持encodingStyle这个属性。

如果你想要实现这个功能,可以按照以下步骤:

  1. 让通过spyne.interface.xml_schema生成的XSD文件支持这个属性。
  2. 实现一个接口,用来插入不同的处理器,以应对不同的encodingStyle值。
  3. 为你需要的encodingStyle值实现不同的处理器。

如果你想要绕过这个问题,可以尝试以下方法:

  1. 切换到软验证模式。
  2. 'method_call'事件中,根据ctx.in_document中的信息编辑ctx.in_object

如果你想进一步讨论,可以在http://lists.spyne.io/listinfo/people上参与。

希望对你有帮助,

撰写回答