web-services - 从 WSDL 构建 SOAP 请求
问题描述
我需要对外部服务器执行 SOAP 请求。我以前从未使用过 SOAP,但我了解 REST 的基础知识。我已收到以下WSDL 文件和此示例查询:
<Messages>
<Version Ds_Version="0.0">
<Message>
<Detail>
<Ds_MerchantCode>999008881</Ds_MerchantCode>
<Ds_Terminal>1</Ds_Terminal>
<Ds_Order>5799L</Ds_Order>
<Ds_TransactionType>3</Ds_TransactionType>
</Detail>
</Message>
</Version>
<Signature>UfECD0KD9Wwo1iqY6PYZoJxw8KwMUz8m18bgLyH3BCI=</Signature>
<SignatureVersion>HMAC_SHA256_V1</SignatureVersion>
</Messages>
我正在使用 Postman 来测试 API。按照我在 Internet 上找到的一些说明,我添加了一个Content-Type
带有值text/xml
的SOAPAction
HTTP 标头和带有consultaOperaciones
WSDL 文件中的值的 HTTP 标头。
我已经设置了这个身体:
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body xmlns:m="http://webservices.apl02.redsys.es">
<m:consultaOperacionesRequest>
<Messages>
<Version Ds_Version="0.0">
<Message>
<Transaction>
<Ds_MerchantCode>999008881</Ds_MerchantCode>
<Ds_Terminal>1</Ds_Terminal>
<Ds_Order>5799L</Ds_Order>
<Ds_TransactionType>3</Ds_TransactionType>
</Transaction>
</Message>
</Version>
<Signature>1KoxTgTakbTprzJ2N/e9JJ8yw/C3QzeNafbUMCNGSFM=</Signature>
<SignatureVersion>HMAC_SHA256_V1</SignatureVersion>
</Messages>
</m:consultaOperacionesRequest>
</soap:Body>
</soap:Envelope>
但是,当我发送请求时,我收到以下错误消息:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<soapenv:Fault>
<faultcode>Server</faultcode>
<faultstring>Internal Error</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
这是一个通用的 SOAP 错误消息,因此我认为问题必须与编码而不是外部服务有关。
提前致谢。
解决方案
在 WSDL 文件中,您将看到 XML 应该作为字符串发送:
<element name="consultaOperaciones">
<complexType>
<sequence>
<element name="cadenaXML" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</element>
因此发送的 XML 应该是:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.apl02.redsys.es">
<soapenv:Header/>
<soapenv:Body>
<web:consultaOperaciones>
<cadenaXML><![CDATA[
<Messages>
<Version Ds_Version="0.0">
<Message>
<Detail>
<Ds_MerchantCode>999008881</Ds_MerchantCode>
<Ds_Terminal>1</Ds_Terminal>
<Ds_Order>5799L</Ds_Order>
<Ds_TransactionType>3</Ds_TransactionType>
</Detail>
</Message>
</Version>
<Signature>UfECD0KD9Wwo1iqY6PYZoJxw8KwMUz8m18bgLyH3BCI=</Signature>
<SignatureVersion>HMAC_SHA256_V1</SignatureVersion>
</Messages>
]]>
</cadenaXML>
</web:consultaOperaciones>
</soapenv:Body>
</soapenv:Envelope>
请注意,我们使用的是 CDATA,因为如前所述,XML 消息应该作为基于 WSDL 的字符串发送。我试过运行它并得到响应:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<p259:consultaOperacionesResponse xmlns:p259="http://webservices.apl02.redsys.es">
<consultaOperacionesReturn><![CDATA[<Messages><Version Ds_Version="0.0"><Message><ErrorMsg><Ds_ErrorCode>XML0023</Ds_ErrorCode></ErrorMsg></Message></Version></Messages>]]></consultaOperacionesReturn>
</p259:consultaOperacionesResponse>
</soapenv:Body>
</soapenv:Envelope>
这意味着您的消息现在正在被解析,因为没有服务器错误并且正在发送看起来合法的consultaOperacionesResponse。该错误似乎与正在发送的数据有关,但通常 API 工作正常。
推荐阅读
- ajax - CakePHP 3:与“onclick 确认”相关的 ajax 请求中的“中断”
- java - 并行布尔值和字符串
- python - 如何在 nifi executescript 处理器中获取测试文件以输出流流文件
- google-bigquery - 如何订购格式化(MMM yyyy)日期?
- neo4j - ModuleNotFoundError:没有名为“py2neo”的模块
- html - Rmarkdown:我们可以将两个单元格与 kableExtra 合并吗?
- javascript - SVG Marker-end 不工作 - 不显示
- sql - 从 generate_series 中获得额外的天数
- google-cloud-functions - 从 GCP 中的 pub/sub Cloud Function 更好地记录日志
- python-sphinx - 在 Sphinx Makefile 代码块中保留选项卡