Mule4使用ApiKit for SOAP映射SOAP响应时命名空间不匹配问题
问题原因
你遇到的问题确实来自命名空间配置和空值序列化逻辑两部分,核心差异点如下:
- 预期中
getPricesResponse节点的**默认命名空间(不带前缀的xmlns)**是http://some.soap.service.pl/xsd,你当前代码把getPricesResponse绑定到了ns0(http://some.soap.service.pl)命名空间下,子节点又绑定了独立的ns01前缀,导致每个子节点都重复声明命名空间。 - 空值字段没有正确输出
xsi:nil="true"属性,且没有提前声明xsi命名空间。 - 额外需要的命名空间没有在
getPricesResponse节点统一声明,导致子节点重复输出冗余配置。
解决方案
直接替换为以下DataWeave代码即可输出符合预期的响应:
%dw 2.0 output application/xml writeDeclaration=false // 声明所有需要用到的命名空间 ns ns2 http://some.soap.service.pl ns ns3 http://sql.java/xsd ns ns4 http://sax.xml.org/xsd ns xsi http://www.w3.org/2001/XMLSchema-instance // 配置默认命名空间,对应预期里的xmlns="http://some.soap.service.pl/xsd" default namespace http://some.soap.service.pl/xsd --- { Envelope @(xmlns:soap: "http://schemas.xmlsoap.org/soap/envelope/"): { Body: { // 统一在getPricesResponse节点声明所有需要的命名空间 getPricesResponse @(xmlns:ns4: ns4, xmlns:ns3: ns3, xmlns:ns2: ns2): { return: { // 空值自动添加xsi:nil属性 dealerNoNabywca: if (payload.return.dealerNoNabywca == null) "" @(xsi:nil: "true") else payload.return.dealerNoNabywca, dealerNoOdbiorca: if (payload.return.dealerNoOdbiorca == null) "" @(xsi:nil: "true") else payload.return.dealerNoOdbiorca, errorType: payload.return.errorType, price1: if (payload.return.price1 == null) "" @(xsi:nil: "true") else payload.return.price1, price2: if (payload.return.price2 == null) "" @(xsi:nil: "true") else payload.return.price2, price3: if (payload.return.price3 == null) "" @(xsi:nil: "true") else payload.return.price3, resultStatus: payload.return.resultStatus } } } } }
如果你的ApiKit for SOAP已经配置了自动包裹SOAP信封,可以移除代码里的Envelope和Body层,只保留getPricesResponse及内部结构即可。
内容的提问来源于stack exchange,提问作者hc0re
相关产品推荐
相关产品推荐

