title: Send ZIP file from vb6 to web service SOAP
body: <p>I have the following code developed in Visual Basic 6.0 (vb6) in which already managed to connect to the web service, but when I send the ZIP file into a byte array returns me an error telling me that the ZIP file is corrupt, obviously I'm not sending ZIP file correctly and that is the reason for the error.</p>
  
  <p>Below the code I use.</p>
  
  <pre><code>Dim strFileName2 As String
  Dim nFile As Integer
  Dim strImage As String
  Dim strBoundary As String
  Dim AsmxUrl As String
  Dim SoapActionUrl As String
  Dim filebytes() As Byte
  Dim Attachment() As Byte
  
  SoapActionUrl = "https://www.sat.gob.mx/ol-ti-itcpgem-beta/billService"
  AsmxUrl = "https://www.sat.gob.mx/ol-ti-itcpgem-beta/billService?wsdl"
  strBoundary = "----=_Part_23_1578679283.1448552263862"
  strFileName2 = "C:\20502264096-01-F001-9672.zip"
  nFile = FreeFile()
  
  Dim adostream As Object
  adostream = CreateObject("ADODB.Stream")
  adostream.Open()
  adostream.Type = 1
  adostream.LoadFromFile strFileName2
  filebytes = adostream.Read
  adostream.Close()
  
  Open strFileName2 For Binary As #nFile
  strImage = String(LOF(nFile), " ")
  Get #nFile, , strImage
  Close #nFile
  
  'message head SOAP
  Xml = "&lt;soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' " &amp; _
              "xmlns:ser='http://service.sat.gob.mx' " &amp; _
              "xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'&gt; " &amp; _
              "   &lt;soapenv:Header&gt;      " &amp; _
              "       &lt;wsse:Security&gt;         " &amp; _
              "           &lt;wsse:UsernameToken&gt;           " &amp; _
              "               &lt;wsse:Username&gt;USUSARIO&lt;/wsse:Username&gt;            " &amp; _
              "               &lt;wsse:Password&gt;CONTRASENA&lt;/wsse:Password&gt; " &amp; _
              "           &lt;/wsse:UsernameToken&gt;      " &amp; _
              "       &lt;/wsse:Security&gt;   " &amp; _
              "   &lt;/soapenv:Header&gt; " &amp; _
              "   &lt;soapenv:Body&gt; " &amp; _
              "       &lt;ser:sendBill&gt; " &amp; _
              "               &lt;!--Optional:--&gt; " &amp; _
              "               &lt;fileName&gt;20502264096-01-F001-9672.zip&lt;/fileName&gt; " &amp; _
              "               &lt;!--Optional:--&gt; " &amp; _
              "               &lt;contentFile&gt;&lt;inc:Include href=""cid:20502264096-01-F001-9672.zip"" xmlns:inc=""http://www.w3.org/2004/08/xop/include""/&gt;&lt;/contentFile&gt;" &amp; _
              "       &lt;/ser:sendBill&gt; " &amp; _
              "   &lt;/soapenv:Body&gt; " &amp; _
              "&lt;/soapenv:Envelope&gt; "
  
  '"               &lt;contentFile&gt;cid:20502264096-01-F001-9672.zip&lt;/contentFile&gt; " &amp; _
  'message attachment
  Attachment = filebytes
  
  'multipart message template
  SendDataS = "--$boundary$" &amp; Chr(10) &amp; _
              "Content-Type: application/xop+xml; charset=UTF-8; type=""text/xml""" &amp; Chr(10) &amp; _
              "Content-Transfer-Encoding: 8bit" &amp; Chr(10) &amp; _
              "Content-ID: &lt;rootpart@soapui.org&gt;" &amp; Chr(10) &amp; _
              "" &amp; Chr(10) &amp; _
              "$xml$" &amp; Chr(10) &amp; _
              "--$boundary$" &amp; Chr(10) &amp; _
              "Content-Type: application/zip; name=20502264096-01-F001-9672.zip" &amp; Chr(10) &amp; _
              "Content-Transfer-Encoding: binary" &amp; Chr(10) &amp; _
              "Content-ID: &lt;20502264096-01-F001-9672.zip&gt;" &amp; Chr(10) &amp; _
              "Content-Disposition: attachment; name=""20502264096-01-F001-9672.zip""; filename=""20502264096-01-F001-9672.zip""" &amp; Chr(10) &amp; _
              " " &amp; Chr(10) &amp; _
              "$Attachment$" &amp; Chr(10) &amp; _
              "--$boundary$" &amp; "--"
  
  'Create objects to DOMDocument and XMLHTTP
  objDom = CreateObject("MSXML2.DOMDocument")
  objXmlHttp = CreateObject("MSXML2.XMLHTTP")
  
  strXmlHead = ""
  strXmlBody = ""
  
  
  'Load XMLHead
  objDom.async = False
  objDom.LoadXml Xml 'aqui carga el XML armado antes
  strXmlHead = objDom.xml 'aqui lee el XML
  
  MsgBox(objDom.xml)
  
  'Load XMLbody
  'objDom.async = False
  'objDom.LoadXml Attachment
  
  MsgBox(Attachment)
  
  'strXmlBody = objDom.LoadXml
  strXmlBody = Attachment
  
  strXml = Replace(SendDataS, "$xml$", strXmlHead)
  strXml = Replace(strXml, "$Attachment$", strXmlBody)
  strXml = Replace(strXml, "$boundary$", strBoundary)
  
  MsgBox(strXml)
  Me.Text1.Text = strXml
  'Open the webservice
  objXmlHttp.Open("POST", AsmxUrl, False)
  
  'Create headings
  objXmlHttp.setRequestHeader("MIME-Version", "1.0")
  objXmlHttp.setRequestHeader("Content-Type", "multipart/related; boundary=""" &amp; strBoundary &amp; """")
  
  objXmlHttp.setRequestHeader("Accept", "application/soap+xml, application/dime, multipart/related, text/*")
  objXmlHttp.setRequestHeader("SOAPAction", """" &amp; SoapActionUrl &amp; """")
  objXmlHttp.setRequestHeader("Content-Length", Len(strXml))
  objXmlHttp.setRequestHeader("Connection", "Close")
  
  'Send XML command
  objXmlHttp.send CStr(strXml) 'objDom.xml
  
  'Get all response text from webservice
  strRet = objXmlHttp.responseText
  MsgBox(strRet)
  </code></pre>