【问题标题】:SOAP MTOM attachments with Linux CURL带有 Linux CURL 的 SOAP MTOM 附件
【发布时间】:2012-08-05 07:09:11
【问题描述】:

到目前为止,我一直在使用简单的 base64 编码通过 SOAP 发送附件并将它们内联 - 全部由 CURL 完成。现在我有一个新请求,附件需要作为 MTOM 附件发送,问题是:linux curl 可以吗?可能我需要multipart/related 或类似的内容类型。

我可以看到使用 JAX-WS 是可能的,但为了做到这一点,我们必须开发一个新客户端,这实际上不是我们的最佳选择。

请告诉我是否可行,如果可行,请给我任何提示。

【问题讨论】:

    标签: linux soap curl mtom


    【解决方案1】:

    您可以将文件内容包含在 base64 编码中并使用 curl post。

    这是一个例子:

    1. 已安装来自axis2 的mtom 示例并为您工作
    2. 构造以下示例 req.xml

    $ cat req.xml

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:mtom="http://ws.apache.org/axis2/mtomsample/" xmlns:xm="http://www.w3.org/2005/05/xmlmime">
       <soap:Header/>
       <soap:Body>
          <mtom:AttachmentRequest>
             <mtom:fileName>one.txt</mtom:fileName>
             <mtom:binaryData xm:contentType="application/txt">SSBhbSB0aGUgZ3JlYXRlc3Qu</mtom:binaryData>
      </mtom:AttachmentRequest>
       </soap:Body>
    </soap:Envelope>
    
    1. 使用 curl 发布请求

    $ cat req.xml | curl -X POST -H '内容类型:应用程序/soap+xml' -d @-
    http://yourmachine.com:8080/axis2/services/MTOMSample.MTOMSampleSOAP12port_http/

    <?xml version='1.0' encoding='UTF-8'?>
    <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
      <soapenv:Body>
        <ns2:AttachmentResponse xmlns:ns2="http://ws.apache.org/axis2/mtomsample/">
          File saved succesfully.
        </ns2:AttachmentResponse>
      </soapenv:Body>
    </soapenv:Envelope>
    

    这对你有用吗?

    【讨论】:

    • base64 编码的二进制数据不是 MTOM/XOP。这只是肥皂。 This link 解释了差异。简而言之:使用 MTOM/XOP,二进制消息内容作为第二个“部分”附加到多部分 MIME 消息中。 SOAP 消息是第一部分。第二部分不是 base64 编码的,所以它节省了 33% 的空间,而且两端也节省了一些 cpu 时间。
    猜你喜欢
    • 2011-04-21
    • 2018-10-27
    • 1970-01-01
    • 2017-06-11
    • 2021-11-24
    • 1970-01-01
    • 2012-07-04
    • 1970-01-01
    • 2014-01-16
    相关资源
    最近更新 更多