使用Spyne定义没有返回消息的SOAP客户端

问题描述

我开始使用Spyne实施Web服务。到目前为止,生成的WSDL对使用方的客户端(机器客户端和人工客户端)来说都是不错的。

唯一的是,他们(人类客户)定义了一个协议,该协议中通过网络服务来回发送的消息不希望返回值(如果您很好奇,那是因为该协议依赖于相反的异步调用在完成某些任务后给出返回反馈的方向。

所以他们要我从WSDL定义中删除相关的回报Message。但是我似乎找不到办法。

class BusinessTransactionLogSend(ServiceBase):
    __service_name__ = "BusinessTransactionLogSend"
    __namespace__ = "tns"
    __port_types__ = ['IBusinessTransactionLogSend']

    @rpc(TransactionLog,_body_style="wrapped",_in_variable_names={'parameters': 'Log'},_args=['Log'],_port_type="IBusinessTransactionLogSend",_returns=None,_out_message_name='LogResponse')
    def Log(ctx,parameters):
        time.sleep(1)

这是服务和RPC Log。我试过放_returns=None,但WSDL仍然有

<wsdl:types>
  <xs:schema targetNamespace="https://www.zz/" elementFormDefault="qualified">
    <xs:import namespace="tns"/>
    <xs:complexType name="LogResponse"/>
    <xs:complexType name="Log">
   ...
   ...
   <wsdl:message name="LogResponse">
     <wsdl:part name="LogResponse" element="tns:LogResponse"/>
   </wsdl:message>
  ...
   <wsdl:portType name="IBusinessTransactionLogSend">
       <wsdl:operation name="Log" parameterOrder="Log">
           <wsdl:input name="Log" message="tns:Log"/>
           <wsdl:output name="LogResponse" message="tns:LogResponse"/>
       </wsdl:operation>
   </wsdl:portType>
   ...

LogResponse消息混淆了他们的SOAP / WSDL解析器。 有什么方法可以跳过此操作或指示Spyne不要为无效的返回值生成Type和Message?

我可以编写一个过滤器(或者可能将其称为事件的侦听器),它看起来似乎是从周围看的,但是

  1. 我还没有找到完整的示例,也没有很好的文档
  2. 在我看来,告诉Spyne做家务比我好

我当然可以尝试告诉我的客户忽略WSDL中的任何xxxResponse消息,但是我担心他们糟糕的基于SAP的客户仍然会抱怨

谢谢 W

解决方法

我发现尚未记录的内容可以解决部分问题:我们可以使用

修饰该方法
@rpc(TransactionLog,_body_style="wrapped",_in_variable_names={'parameters': 'Log'},_is_async=True,#<====================== THIS ======
         _args=['Log'],_port_type="IBusinessTransactionLogSend",_returns=None
         )

这将摆脱此WSDL片段中的output部分

    <wsdl:portType name="IBusinessTransactionLogSend">
        <wsdl:operation name="Log" parameterOrder="Log">
            <wsdl:input name="Log" message="tns:Log"/>
            <wsdl:output name="LogResponse" message="tns:LogResponse"/>
        </wsdl:operation>
    </wsdl:portType>

现在是

    <wsdl:portType name="IBusinessTransactionLogSend">
        <wsdl:operation name="Log" parameterOrder="Log">
            <wsdl:input name="Log" message="tns:Log"/>
        </wsdl:operation>
    </wsdl:portType>

但是,即使没有人使用,Message和ComplexType LogResponse仍然存在于WSDL中。