node.js - “无法读取未定义的属性方法名称”使用具有文档样式的 NodeJS SOAP 方法
问题描述
我有一个 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>
邮递员请求:
<?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 'methodName' 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>
推荐阅读
- r - 通过 R 使用 Linux Azure DSVM 进行 SSH 公钥身份验证
- python - python 的 dict .get() 方法如何检查默认参数?
- java - Flink:可以在 X 时间后删除 Queryable 状态吗?
- c# - 如何使用类库(.NET Framework)在 C# 中创建文件 excel?
- php - Symyfony 3.4 - 如何将实体移动到其他数据库
- python - 如何读取 Spark 日志文件?.Iz4 或 .snappy
- wordpress - 是否可以防止 cloudflare 缓存我的图像?
- r - 一种更快(矢量化)的方法来创建具有预定长度的 1 和 0 的滑动序列
- linux - libQt5Core.so.5 在 docker fedora:29 中格式错误
- php - 尝试使用 Symfony 模板组件加载模板时,您请求了一个不存在的参数“名称”错误