如何阻止Spyne将参数包装在complexType中?

2 投票
1 回答
898 浏览
提问于 2025-04-17 18:59

我正在尝试使用Spyne从Python提供网络服务。我已经为一个叫做SayHello(name, times)的测试函数做好了所有的工作。不过,我在想,为什么Spyne要把name和times这两个参数包裹在一个叫做SayHello的复杂类型里?这让我们在.NET中使用这个网络服务变得很麻烦(也就是说,我不能直接用appClient.SayHello("Dave", 5),而是得先写SayHello args = new SayHello(); args.name = "Dave"; args.times = "5"; appClient.SayHello(args);,这样显得很不优雅)。

有没有办法让Spyne不把参数包裹在复杂类型里呢?

这是Spyne生成的当前wsdl中相关的部分:

<xs:schema targetNamespace="solutions.sfcs" elementFormDefault="qualified">
  <xs:complexType name="SayHello">
    <xs:sequence>
      <xs:element name="name" type="xs:string" minOccurs="0" nillable="true"/>
      <xs:element name="times" type="xs:integer" minOccurs="0" nillable="true"/>
    </xs:sequence>
  </xs:complexType>

1 个回答

2

你可以在 @rpc 装饰器里加上 _body_style='bare' 这个参数,这样就可以避免被包裹起来。但这样做你很可能会遇到:

Exception: body_style='bare' can handle at most one function argument.

如果你能找到一个方法来解决这个问题,而且不会影响到其他的测试,我就可以把你的修改合并进来了。

撰写回答