You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SOAP请求反序列化失败:InsertPayments接口报错排查

调用InsertPayments接口反序列化异常的解决方法

问题描述

调用InsertPayments接口时触发反序列化异常,报错信息:

格式化程序尝试反序列化消息时抛出异常:反序列化操作“InsertPayments”的请求消息正文出错。预期命名空间“http://tempuri.org/”的结束元素“InputXML”,却找到命名空间“http://tempuri.org/”的元素“engine”。第8行,第13位。

测试验证:

  • 发送纯文本“Test”时请求正常,对应SOAP Body:
<soap:Body>
        <InsertPayments xmlns="http://tempuri.org/">
            <InputXML>
            Test
            </InputXML>
        </InsertPayments>
    </soap:Body>
  • 直接嵌套XML节点时触发错误,对应SOAP Body:
<soap:Body>
        <InsertPayments xmlns="http://tempuri.org/">
            <InputXML>
                <engine>
                    <engineversion>1</engineversion>
                    <serverculture>en-ZA</serverculture>
                    <requestingpersonname>pieter.swanepoel</requestingpersonname>
                    <authcode>9631853F-38CA-45BD-8DFE-E70FC445F8EB</authcode>
                </engine>
            </InputXML>
        </InsertPayments>
    </soap:Body>

核心原因

接口期望InputXML节点内是纯文本格式的XML内容,而非直接嵌套XML节点。直接放置<engine>节点时,SOAP解析器会将其识别为同命名空间下的SOAP节点,而非InputXML的文本值,导致解析逻辑混乱。

解决方法

方法1:转义XML内容为纯文本

将<engine>及其内部的XML代码进行转义,把<替换为&lt;,>替换为&gt;,让解析器将这段内容识别为InputXML的文本值。修改后的SOAP Body:

<soap:Body>
        <InsertPayments xmlns="http://tempuri.org/">
            <InputXML>
                &lt;engine&gt;
                    &lt;engineversion&gt;1&lt;/engineversion&gt;
                    &lt;serverculture&gt;en-ZA&lt;/serverculture&gt;
                    &lt;requestingpersonname&gt;pieter.swanepoel&lt;/requestingpersonname&gt;
                    &lt;authcode&gt;9631853F-38CA-45BD-8DFE-E70FC445F8EB&lt;/authcode&gt;
                &lt;/engine&gt;
            </InputXML>
        </InsertPayments>
    </soap:Body>

方法2:用CDATA包裹XML内容

CDATA块会告知SOAP解析器,内部内容为纯文本,无需解析为XML节点。修改后的SOAP Body:

<soap:Body>
        <InsertPayments xmlns="http://tempuri.org/">
            <InputXML>
                <![CDATA[
                <engine>
                    <engineversion>1</engineversion>
                    <serverculture>en-ZA</serverculture>
                    <requestingpersonname>pieter.swanepoel</requestingpersonname>
                    <authcode>9631853F-38CA-45BD-8DFE-E70FC445F8EB</authcode>
                </engine>
                ]]>
            </InputXML>
        </InsertPayments>
    </soap:Body>

两种方法均可让接口正确识别InputXML内的XML内容,避免反序列化异常。

内容的提问来源于stack exchange,提问作者user2389448

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 12:01:01