我一直在研究如何使用 SOAP 消息处理二进制数据。我正在开发客户端和服务,所以我可以选择任何一个框架。唯一的限制是Service端已经设计好了,并且是基于Spring-WS的。
google了一下,貌似有3种选择:
- 在 SOAP 消息 (Base64Binary) 中以 base64 形式内联发送附件。
- 在 SOAP 消息之外发送附件。即引用附件 (SWA)
- 在邮件外发送附件,但使其看起来像是嵌入在邮件中 (MTOM)。
问题
他们说附件在 SOAP 消息之外到底是什么意思?我假设附件可能是作为不同的 TCP 包发送的,但我想我错了?
建议使用以上选项中的哪一个,具体来说,哪个选项最适合 Spring 的 Spring-WS 框架?
我不清楚上述哪些选项在传输过程中对二进制内容进行了编码。此处描述的二进制 MIME 是什么 - http://www.crosschecknet.com/intro_to_mtom.php ?二进制数据在传输过程中是否仍然转换为文本?
使用SWA时数据的格式是什么?
最佳答案
What exactly does it mean when they say that the attachement is outside of the SOAP message? I assume that maybe the attachement is sent as a different TCP package but i think i am wrong?
与第一个选项相比,附件不是实际 soap 消息负载的一部分,而是在 SOAP 文档中引用。 MTOM 和 SWA 之间的区别在于引用文件所在的位置。对于 MTOM,它嵌入在响应中,而在 SWA 中,您可以获得例如网络资源的链接。它遵循 3 个最小示例:
MTOM(xop+xml 类型的多合一响应)
Content-type: multipart/related;
type="application/xop+xml";
start-info="text/xml"
--uuid:c73c9ce8-6e02-40ce-9f68-064e18843428
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary
<?xml version="1.0" ?>
<S:Envelope xmlns:S="...">
<S:Body>
<ns2:downloadImageResponse xmlns:ns2="...">
<return>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include"
href="cid:012eb00e-9460-407c-b622-1be987fdb2cf@example.jaxws.sun.com">
</xop:Include>
</return>
</ns2:downloadImageResponse>
</S:Body>
</S:Envelope>
--uuid:c73c9ce8-6e02-40ce-9f68-064e18843428
Content-Id: <012eb00e-9460-407c-b622-1be987fdb2cf@example.jaxws.sun.com>
Content-Type: image/png
Content-Transfer-Encoding: binary
SWA(仅供引用)
Content-Type: application/xml;charset=utf-8;
<?xml version="1.0" ?>
<S:Envelope xmlns:S="...">
<S:Body>
<ns2:downloadImageResponse xmlns:ns2="...">
<return>
https://server.com/downloadImagehere.png
</return>
</ns2:downloadImageResponse>
</S:Body>
</S:Envelope>
内联
Content-Type: application/xml;charset=utf-8;
<?xml version="1.0" ?>
<S:Envelope xmlns:S="...">
<S:Body>
<ns2:downloadImageResponse xmlns:ns2="...">
<return>
YTM0NZomIz...potentiallyLargeBase64encodedFileGoesInHere...I2OTsmIzM0NTueYQ==
</return>
</ns2:downloadImageResponse>
</S:Body>
</S:Envelope>
Which of the above options is recommended and specifically, which one works best with Spring's Spring-WS framework?
它们都受支持,使用哪种取决于您的用例。根据我的研究,MTOM 似乎是事实上的标准。根据我的说法,如果您有大型或多个文件附件,它特别有用。由于它将消息拆分为逻辑组件,因此它可能会为解析器提供更多选项来有效地处理二进制数据。
但是,对于较小的数据,我可能会选择资源的嵌入,因为它是标准 SOAP 协议(protocol)的一部分,并且只直接使用编码的字节数组,然后将其直接嵌入到消息中。如果可移植性/兼容性很重要,这可能是可供选择的方法。
最后一种方法显然需要您自己处理引用,这可能是也可能不是您想要的。
It is unclear to me which of the above options encode the binary content during transmission. What is Binary MIME as described here - http://www.crosschecknet.com/intro_to_mtom.php ? Is the binary data still converted to text during transmission?
MTOM 和 Inline 都通常将文件编码为 Base64 编码的字符串。对于外部链接,它不相关。
What is the format of the data when using SWA?
Base64编码字节数组
关于java - 使用 SOAP 处理二进制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9968168/