VB6 base64二进制

时间:2010-08-11 19:44:45

标签: web-services soap vb6 base64

我在这个网络服务上遇到了问题:

http://credenciados.pronto.com.br/carga.asmx?op=IncluirMultimidia2

arrayArquivo 参数上,我使用此函数生成数据:

Private Function getBase64fromFile(Filename) As String

   Dim base64 As New cls64base

   Dim FileInputData() As Byte

   Open Filename For Binary As #1
   FileInputData = String(LOF(1), 0)
   Get #1, 1, FileInputData
   Close #1

   getBase64fromFile = base64.Base64Encode(FileInputData)

End Function

当我拨打该服务时,我收到此错误:

元素arrayArquivo的类型转换失败

观测值:

我正在使用:

  • Microsoft Soap ToolKit 3.0
  • Visual Basic 6

1 个答案:

答案 0 :(得分:3)

我不确定这个问题是什么,但我使用以下一对例程从文件中获取二进制数据,然后base64对其进行编码。代码需要MSXML库 - 我使用版本3,它应该适用于所有Win2K +版本。

从文件中获取二进制数据:

Public Function GetFileData(ByVal Filename As String) As Byte()

    Dim f As Integer

    f = FreeFile

    Open Filename For Binary Access Read As #f
    ReDim GetFileData(0 To LOF(f) - 1)
    Get #f, , GetFileData
    Close #f

End Function

将字节数组转换为base64字符串:

Public Function GetBase64String(ByRef data() As Byte) As String

    Dim doc As DOMDocument
    Dim root As IXMLDOMElement

    Set doc = New DOMDocument
    Set root = doc.createElement("encode")
    root.dataType = "bin.base64"
    root.nodeTypedValue = data

    GetBase64String = root.Text

Exit Function