如何编辑节点肥皂中的响应字段

how to edit the response fields in node-soap

我有以下 WSDL 定义:

<definitions targetNamespace="http://app.com/app" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:app="http://app.com/app" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   
   <message name="SoapQuery">
      <part name="TransType" type="xsd:string" />
   </message>

   <message name="SoapQueryResult">
      <part name="ResponseCode" type="xsd:string"/>
      <part name="ResultDesc" type="xsd:string" />
   </message>

   <portType name="SoapQuery_PortType">
      <operation name="SoapQuery">
         <input message="SoapQuery" />
         <output message="SoapQueryResult" />
      </operation>
   </portType>

   <binding name="SoapQuery_Binding" type="SoapQuery_PortType">
      <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
      <operation name="SoapQuery" style="document">
         <soap:operation soapAction="SoapQuery" />
         <soap:input>
            <soap:body namespace="app" use="literal" />
         </soap:input>

         <soap:output>
            <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal" />
         </soap:output>
      </operation>
   </binding>

   <service name="SoapQueryService">
      <documentation>WSDL File for SoapQueryService</documentation>
      <port binding="SoapQuery_Binding" name="SoapQuery_Port">
         <soap:address location="http://localhost:8002/api/request" />
      </port>
   </service>
</definitions>

和以下处理程序定义:

var SoapQueryService = {
  SoapQueryService: {
    SoapQuery_Port: {
      // This is how to define an asynchronous function.
      SoapQuery: function (args, callback) {
        // do some work
        callback({
          'ResultCode': 0,
          'ResultDesc': "sdfds",
        });
      }
    }
  }
};

当前,当收到以下请求时:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <app:SoapQuery xmlns:app="http://app.com/app">
            <TransType>11124</TransType>
        </app:SoapQuery>
    </soapenv:Body>
</soapenv:Envelope>

它returns:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:app="http://app.com/app">
  <soap:Body>
    <app:SoapQueryResponse>
      <app:ResultCode>0</app:ResultCode>
      <app:ResultDesc>sdfds</app:ResultDesc>
    </app:SoapQueryResponse>
  </soap:Body>
</soap:Envelope>

但我希望响应看起来像:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:app="http://app.com/app">
  <soap:Body>
    <app:SoapQueryResult> <!-- not - SoapQueryResponse -->
      <ResultCode>0</ResultCode>  <!-- notice there is no `app:` -->
      <ResultDesc>sdfds</ResultDesc> <!-- notice there is no `app:` -->
    </app:SoapQueryResult>
  </soap:Body>
</soap:Envelope>

我尝试了不同的方法,但 none 似乎对响应类型有影响。我觉得我在 WSDL 或处理程序中遗漏了一些东西..

省略 WSDL 定义中的 RPC 标记并将其更改为

<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />

因为您使用 RPC 作为样式,所以它向输出消息和部分添加 app:,忽略您的 outputName 并将其替换为 SoapQueryResponse .删除 RPC 标签会给你这个输出

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:app="http://app.com/app">
  <soap:Body>
    <SoapQueryResult> <!-- notice there is no `app:` -->
      <ResultCode>0</ResultCode>  
      <ResultDesc>sdfds</ResultDesc>
    </SoapQueryResult>
  </soap:Body>
</soap:Envelope>

默认情况下,node-soap 将从消息和消息部分中删除所有 targetNamespace 前缀(如果未进行程式化 RPC)。我创建了一个拉取请求 here,它允许用户在输出消息上添加可选的 targetNamespace,以便仅在输出而不是部分上添加前缀。因此,根据建议的拉取请求,您可以将 targetNamespace 添加到您的消息

 <message name="SoapQueryResult" targetNamespace="app">
      <part name="ResponseCode" type="xsd:string"/>
      <part name="ResultDesc" type="xsd:string" />
 </message>

你会得到你想要的输出

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:app="http://app.com/app">
  <soap:Body>
    <app:SoapQueryResult>
      <ResultCode>0</ResultCode>
      <ResultDesc>sdfds</ResultDesc>
    </app:SoapQueryResult>
  </soap:Body>
</soap:Envelope>