如何在VB6中下载MTOM附件

时间:2018-06-04 09:52:23

标签: web-services vb6 mtom

请有人向我展示一个如何下载MTOM附件并使用VB6将其保存到磁盘的示例?

目前,我可以使用此代码从我的ws获得回复:

Dim objDom As Object
Dim objXmlHttp As Object
Dim strRet As String
Dim intPos1 As Integer
Dim intPos2 As Integer
On Error GoTo Err_PW
' Create objects to DOMDocument and XMLHTTP
Set objDom = CreateObject("MSXML2.DOMDocument")
Set objXmlHttp = CreateObject("MSXML2.XMLHTTP")

'Set objXmlHttp = New MSXML2.XMLHTTP40
' Load XML
objDom.async = False
objDom.loadXML XmlBody

' Open the webservice
objXmlHttp.Open "POST", AsmxUrl, False
' Create headings
objXmlHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXmlHttp.setRequestHeader "SOAPAction", SoapActionUrl

' Send XML command
objXmlHttp.Send (objDom.xml)
' Get all response text from webservice
strRet = objXmlHttp.responseText

但从这一点来说,我不知道如何继续抓住MTOM附件。

这是从ws返回的:

--uuid:0b9372cf-63bb-484f-87f3-7bedfaa776fb
Content-Id: <rootpart*0b9372cf-63bb-484f-87f3-7bedfaa776fb@example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:getContentStreamResponse xmlns:ns2="http://docs.oasis-open.org/ns/cmis/messaging/200908/" xmlns="http://docs.oasis-open.org/ns/cmis/core/200908/">
<ns2:contentStream>
<ns2:length>2572861</ns2:length>
<ns2:mimeType>application/vnd.openxmlformats-officedocument.wordprocessingml.document</ns2:mimeType>
<ns2:filename>SF-MASTER - SDTC.docx</ns2:filename>
<ns2:stream>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:4b7c8c60-fc9e-4da8-92fc-aa8c2fdfb401@example.jaxws.sun.com"/></ns2:stream>
</ns2:contentStream>
</ns2:getContentStreamResponse>
</S:Body>
</S:Envelope>
--uuid:0b9372cf-63bb-484f-87f3-7bedfaa776fb
Content-Id: <4b7c8c60-fc9e-4da8-92fc-aa8c2fdfb401@example.jaxws.sun.com>
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Transfer-Encoding: binary

PK
31/05/2018 10:04:06: UUID documento: 0b9372cf-63bb-484f-87f3-7bedfaa776fb
31/05/2018 10:04:06: Tag finale: --uuid:0b9372cf-63bb-484f-87f3-7bedfaa776fb--
31/05/2018 10:04:06: lunghezza documento: 2572861

非常感谢

1 个答案:

答案 0 :(得分:-1)

Use this as a guide并修改您的代码以将返回的文件数据保存为二进制文件。

添加到功能

Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2

Dim varByteArray, ado
Dim strFile as String

发送请求后,请插入此代码

If objXmlHttp.Status <> "200" Then
    Exit Function
End If

' Pull this from returned header data
strFile = "SF-MASTER - SDTC.docx"

' get file contents
varByteArray = objXmlHttp.ResponseBody

Set objXmlHttp= Nothing

'Now save the binary file
On Error Resume Next
Set ado = Nothing
Set ado = CreateObject("ADODB.Stream")
ado.Type = adTypeBinary
ado.Open
ado.Write varByteArray
ado.SaveToFile strFile, adSaveCreateOverWrite
ado.Close