对 WCF 的服务响应包括重复的命名空间和标记前缀
本文关键字:命名空间 前缀 包括重 WCF 服务 响应 | 更新日期: 2023-09-27 18:34:41
Question:
-
为什么我会收到包含重复标记前缀命名空间的 SOAP 响应片段?
-
为什么我会在 SoapUI 中收到与使用完全相同的 SOAP 请求的 WCF 客户端不同的响应片段?
上下文:
我正在使用 WCF 客户端调用基于 Java 的第三方 Web 服务。当使用导致错误响应的错误值进行调用时,从第三方 WS 发送的 SOAP 片段响应包含 Fault 标记行上 SOAP 信封的重复命名空间和标记前缀。这会导致 WCF 抛出一个 CommunicationException,其中包含 XmlException 的 innerException,该异常引用以下内容作为错误:
从命名空间"开始元素"错误代码"预期。找到元素 'SOAP-ENV:faultcode' 从命名空间"http://schemas.xmlsoap.org/soap/envelope/"。
此错误消息使我相信 SOAP 片段中重复的命名空间是罪魁祸首。奇怪的是,使用从 WCF 客户端发送到 SoapUI 中的 Web 服务的确切 SOAP 请求不会导致此命名空间在 SOAP 响应片段中重复。
WCF 客户端正在使用 basicHttpBinding。
请参阅下面的请求的 SOAP 片段、通过 WCF 的响应和通过 SoapUI 的响应。
WCF 和 SoapUI 发送的请求:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Search xmlns="urn:ent.soap.testservice.com/objs">
<Request objType="Report">
<RequestorId>ABCD</RequestorId>
<TargetId></TargetId>
</Request>
</Search>
</s:Body>
</s:Envelope>
WCF 客户端收到的响应:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:faultcode>SOAP-ENV:Server</SOAP-ENV:faultcode>
<SOAP-ENV:faultstring>Invalid action parameters</SOAP-ENV:faultstring>
<SOAP-ENV:detail>
<fns:fault xmlns:fns="urn:fault.soap.testservice.com" xmlns:java="java" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="fns:ApiFault">
<fns:exceptionCode>INTERNAL_ERROR</fns:exceptionCode>
<fns:exceptionMessage>Invalid action parameters</fns:exceptionMessage>
<fns:logDataExchangeId>1234567890</fns:logDataExchangeId>
</fns:fault>
</SOAP-ENV:detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SoapUI 收到的响应:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<SOAP-ENV:faultcode>SOAP-ENV:Server</SOAP-ENV:faultcode>
<SOAP-ENV:faultstring>Invalid action parameters</SOAP-ENV:faultstring>
<SOAP-ENV:detail>
<fns:fault xsi:type="fns:ApiFault" xmlns:fns="urn:fault.soap.testservice.com" xmlns:java="java" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fns:exceptionCode>INTERNAL_ERROR</fns:exceptionCode>
<fns:exceptionMessage>Invalid action parameters</fns:exceptionMessage>
<fns:logDataExchangeId>1234567890</fns:logDataExchangeId>
</fns:fault>
</SOAP-ENV:detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
问题不在于重复的命名空间声明。问题出在这一位:
<SOAP-ENV:faultcode>SOAP-ENV:Server</SOAP-ENV:faultcode>
<SOAP-ENV:faultstring>Invalid action parameters</SOAP-ENV:faultstring>
在 SOAP 规范中,错误代码和错误字符串元素位于空的默认命名空间中,而不是位于"http://schemas.xmlsoap.org/soap/envelope/"命名空间中。所以它真的应该看起来像这样:
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:MustUnderstand</faultcode>
<faultstring>SOAP Must Understand Error</faultstring>
</SOAP-ENV:Fault>
因此,看起来此服务特别不符合 SOAP 1.1(或 1.2(规范。