'Cannot read property methodName of undefined' 使用文档样式使用 NodeJS SOAP 方法

'Cannot read property methodName of undefined' consuming a NodeJS SOAP method with document style

我有一个 NodeJS (node-soap) SOAP Web 服务,当我通过 POSTMAN 使用它时,它适用于 rpc 样式,但我需要使其适用于文档样式。当我改变风格时,我有一个例外,没有太多信息。接下来的细节:

WSDL(适用于样式 rpc):

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
  name="files_service"
  targetNamespace="http://localhost:4205/files_service"
  xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
  xmlns:s="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:tns="http://localhost:4205/files_service">
  <wsdl:types>
    <xs:schema targetNamespace="http://localhost:4205/files_service" xmlns="http://localhost:4205/files_service" attributeFormDefault="qualified" elementFormDefault="qualified">

      <xs:element name="GetFilesRequest">
        <xs:complexType>
          <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="1" name="User" type="xs:string"/>
            <xs:element minOccurs="0" maxOccurs="1" name="Password" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>

      <xs:element name="GetFilesResponse">
        <xs:complexType>
          <xs:sequence>
              <xs:any/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>

    </xs:schema>
  </wsdl:types>
  <wsdl:message name="GetFilesSoapIn">
    <wsdl:part name="parameters" element="tns:GetFilesRequest"/>
  </wsdl:message>
  <wsdl:message name="GetFilesSoapOut">
    <wsdl:part name="parameters" element="tns:GetFilesResponse"/>
  </wsdl:message>
  <wsdl:portType name="pull_files">
    <wsdl:operation name="GetFiles">
      <wsdl:input message="tns:GetFilesSoapIn"/>
      <wsdl:output message="tns:GetFilesSoapOut"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="pull_files_binding" type="tns:pull_files">
    <s:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
    <wsdl:operation name="GetFiles">
      <s:operation soapAction="GetFiles"/>
      <wsdl:input>
        <s:body use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </wsdl:input>
      <wsdl:output>
        <s:body use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="files">
    <wsdl:port binding="tns:pull_files_binding" name="pull">
      <s:address location="http://localhost:4205/files_service"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

响应是这样的:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:tns="http://localhost:4205/files_service">
    <soap:Body>
        <tns:GetFilesResponse>
            <tns:GetFilesResult>
                <tns:File>
                    <Name></Name>
                    <Dir></Dir>
                </tns:File>
            </tns:GetFilesResult>
        </tns:GetFilesResponse>
    </soap:Body>
</soap:Envelope>

POSTMAN 请求:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http:localhost:4205/files_service">
  <soap:Body>
    <tns:GetFiles>
      <tns:User>myusername</tns:User>
      <tns:Password>mypassword</tns:Password>
    </tns:GetFiles>
  </soap:Body>
</soap:Envelope>

在 WSDL 中更改文档样式时出错 <s:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:tns="http://localhost:4205/files_service">
    <soap:Body>
        <soap:Fault>
            <soap:Code>
                <soap:Value>SOAP-ENV:Server</soap:Value>
                <soap:Subcode>
                    <soap:value>InternalServerError</soap:value>
                </soap:Subcode>
            </soap:Code>
            <soap:Reason>
                <soap:Text>TypeError: Cannot read property &apos;methodName&apos; of undefined</soap:Text>
            </soap:Reason>
        </soap:Fault>
    </soap:Body>
</soap:Envelope>

我不知道为什么文档样式会失败。另一件事是,如果我使用来自 node-soap 客户端的方法,我没有异常,我会正确获取数据。

回答我的问题,在请求中我不需要定义方法,我需要定义请求。我使用 SoapUI 来获取正确的请求。

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http:localhost:4205/files_service">
  <soap:Body>
    <tns:GetFilesRequest>
      <tns:User>myuser</tns:User>
      <tns:Password>mypass</tns:Password>
    </tns:GetFilesRequest>
  </soap:Body>
</soap:Envelope>