具有两个元素的 SOAP 主体 [英] SOAP Body with Two Elements

查看:35
本文介绍了具有两个元素的 SOAP 主体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建具有以下结构的soap消息:

I am trying to create a soap message with the following structure:

<SOAP:Envelope>
    <SOAP:Header/>
    <SOAP:Body>
        <Item1/>
        <Item2/>
    </SOAP:Body>
</SOAP:Envelope>

我正在使用 WebServiceMessageCallback 来获取上述格式,但是当我尝试使用新源转换正文时,其中源具有上述格式:

I am using a WebServiceMessageCallback to get the above format, but when I try and transform the body with the new source, where source has the above format:

TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(source, soapBody.getPayloadResult());

我收到以下错误:

[Fatal Error] :1:157: The markup in the document following the root element must be well-formed.
ERROR:  'The markup in the document following the root element must be well-formed.'
    Exception in thread "main" org.springframework.ws.client.WebServiceTransformerException:Transformation error: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 157; The markup in the document following the root element must be well-formed.; nested exception is javax.xml.transform.TransformerException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 157; The markup in the document following the root element must be well-formed.

我的理解是这个错误告诉我主体不是格式良好的 XML,因为它没有单个根元素.但是,这正是我需要的,因为我将消息发送到期望上述结构的服务.

My understanding is that this error is telling me that the body is not well-formed XML because it doesn't have a single root element. However, that is what I need as the service I am sending the message to expects the above structure.

有什么办法可以解决这个问题吗?感谢您的帮助.

Is there some way around this? Thanks for any help.

我应该提到我已经看到 Spring Update SOAP Header with Two Elements,这就是我想要做的,但在标题中.我尝试过他使用虚拟根的方法,但我不确定如何在他提到的转换后移除虚拟根.我没有足够的代表来评论他的答案以找出...

I should mention that I have seen Spring Update SOAP Header with Two Elements, which is what I am trying to do but in the header instead. I have tried his method of using a dummy root, but I am not sure how to remove the dummy root after the transformation as he mentions. I don't have enough rep to comment on his answer to find out...

推荐答案

元素 包含您要交换的消息.因此,在 中放入两个元素是不可能的.您必须将根 XML 元素包装在您的两个项目周围.

The element <SOAP:Body> contains the message you want to exchange. Putting in two elements in a <SOAP:Body> is therefore not possible. You have to wrap a root XML element around your two items.

这篇关于具有两个元素的 SOAP 主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆