美文网首页
第二十八章 使用 MTOM 进行附件 - 具有 MTOM 封装的

第二十八章 使用 MTOM 进行附件 - 具有 MTOM 封装的

作者: Cache技术分享 | 来源:发表于2024-06-14 08:22 被阅读0次

第二十八章 使用 MTOM 进行附件 - 具有 MTOM 封装的 SOAP 消息

具有 MTOM 封装的 SOAP 消息

打包 SOAP 消息的另一种方法是使用 MTOM(消息传输优化机制)规范中所述的 MIME 部分。二进制数据可以放入单独的 MIME 部分中,而无需进行 base-64 编码。SOAP 消息会根据需要包含对单独部分的引用。例如(为便于阅读添加了换行符和空格):

HTTP/1.1 200 OK
Date: Wed, 19 Nov 2008 21:54:57 GMT
Server: Apache
SET-COOKIE: CSPSESSIONID-SP-8080-UP-csp-gsoap-=003000010
000247guhlx000000NW1KN5UtWg$CWY38$bbTOQ--; path=/csp/mysamples/;
CACHE-CONTROL: no-cache
EXPIRES: Thu, 29 Oct 1998 17:04:19 GMT
MIME-VERSION: 1.0
PRAGMA: no-cache
TRANSFER-ENCODING: chunked
Connection: close
Content-Type: multipart/related; type="application/xop+xml"; 
boundary=--boundary388.5294117647058824932.470588235294118--; 
start="<0.B1150656.EC8A.4B5A.8835.A932E318190B>"; start-info="text/xml"

1ddb
----boundary388.5294117647058824932.470588235294118--
Content-Type: application/xop+xml; type="text/xml"; charset="UTF-8"
Content-Transfer-Encoding: 8bit
Content-Id: <0.B1150656.EC8A.4B5A.8835.A932E318190B>

<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV='https://schemas.xmlsoap.org/soap/envelope/' 
xmlns:xsi='https://www.w3.org/2001/XMLSchema-instance' 
xmlns:s='https://www.w3.org/2001/XMLSchema'>
<SOAP-ENV:Body>
<DownloadResponse xmlns="https://www.filetransfer.org">
<DownloadResult>
   <Filename>sample.pdf</Filename>
   <IsBinary>true</IsBinary>
   <BinaryContents>
      <xop:Include href="cid:1.B1150656.EC8A.4B5A.8835.A932E318190B" 
              xmlns:xop="https://www.w3.org/2004/08/xop/include"/>
   </BinaryContents></DownloadResult></DownloadResponse>  
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
----boundary388.5294117647058824932.470588235294118--
Content-Id: <1.B1150656.EC8A.4B5A.8835.A932E318190B>
Content-Transfer-Encoding: binary
CONTENT-TYPE: application/octet-stream


[very long binary content not shown here]

与默认包相比,请注意以下差异:

  • 该消息具有 MIME 部分,因此包含边界。
  • MIME 部分具有 Content-ID 属性。
  • SOAP 主体中,元素 BinaryContents 包含对该内容 ID 的引用。

带附件的 SOAP

打包SOAP 消息的第三种方法是使用带附件的 SOAP 规范,该规范也使用 MIME 部分,但打包消息的方式与 MTOM 略有不同。以下是示例(为便于阅读添加了换行符和空格):

HTTP/1.1 200 OK
Date: Mon, 09 Nov 2009 17:47:36 GMT
Server: Apache
SET-COOKIE: CSPSESSIONID-SP-8080-UP-csp-gsoap-=
000000010000213eMwn70000004swjTo4cGuInLMU1n7jaPg--; path=/csp/mysamples/;
CACHE-CONTROL: no-cache
EXPIRES: Thu, 29 Oct 1998 17:04:19 GMT
MIME-VERSION: 1.0
PRAGMA: no-cache
TRANSFER-ENCODING: chunked
Connection: close
Content-Type: multipart/related; type="text/xml";
 boundary=--boundary2629.3529411764705883531.411764705882353--

1ca2
----boundary2629.3529411764705883531.411764705882353--
Content-Type: text/xml; charset="UTF-8"
Content-Transfer-Encoding: 8bit

<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV='https://schemas.xmlsoap.org/soap/envelope/' 
xmlns:xsi='https://www.w3.org/2001/XMLSchema-instance' 
xmlns:s='https://www.w3.org/2001/XMLSchema'>
  <SOAP-ENV:Body><DownloadBinaryResponse xmlns="https://www.filetransfer.org">
<DownloadBinaryResult>MQ==</DownloadBinaryResult></DownloadBinaryResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
----boundary2629.3529411764705883531.411764705882353--
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream

%PDF-1.4
%âãÏÓ
86 0 obj
<</Length 87 0 R
/Filter /FlateDecode
>>
stream
[stream not shown]

MTOM 一样,有一个边界字符串,附件是 MIME 部分。但是,与 MTOM 不同的是,MIME 部分没有内容 IDSOAP 主体不包含对 MIME 部分的任何引用。

相关文章

网友评论

      本文标题:第二十八章 使用 MTOM 进行附件 - 具有 MTOM 封装的

      本文链接:https://www.haomeiwen.com/subject/fhzoqjtx.html