我在使用 SOAP 的 API 时遇到了问题。我的客户端是用PHP编写的,并产生以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://webportal.gb.co.uk/GBPortal" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns1:CreateAuthenticatedSession xsi:type="ns1:CreateAuthenticatedSession">
<szUsername xsi:type="xsd:string">...</szUsername>
<szPassword xsi:type="xsd:string">...</szPassword>
</ns1:CreateAuthenticatedSession>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
文档中的参考 XML 是:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CreateAuthenticatedSession xmlns="http://webportal.gb.co.uk/GBPortal">
<szUsername>string</szUsername>
<szPassword>string</szPassword>
</CreateAuthenticatedSession>
</soap:Body>
</soap:Envelope>
据我所知,这在功能上是相同的。
我错过了导致 API 拒绝 XML 的任何差异吗?不希望使用字符串串联来生成 XML。
编辑:如果没有功能差异,请留下答案。
这两个请求在功能上是相同的。客户端生成的那个只是对<Envelop>
和<Body>
使用不同的命名空间名称,但这仍然指向与文档版本相同的命名空间(http://schemas.xmlsoap.org/soap/envelope/
)。
此外,客户端版本在 CreateAuthenticatedSession
元素上使用命名空间,而文档版本仅声明 xmlns
属性。