VB Fax – Retrieve an Inbound Fax Image

Download the VB fax (VB6) code samples.

In this sample, the GetImageChunkEx2 method retrieves an image for a received (inbound) VB fax.

To retrieve the fax image, you need the fax message ID, which is retrieved using the method GetList2.

In the VB6 fax code sample below, you retrieve a fax image in multiple chunks (the chunk size is configurable):


Attribute VB_Name = "GetImageChunkEx2"
Option Explicit
'
' This sample gets an entire VB fax message from the Inbound queue and saves it to a local file.
' Message is being retrieved in chunks, to optimize performance.
' A typical usage would be to call this method for each item retreived by the GetList2() method
'
Const MessageID As Long = 30476113   ' Specify ID of message to be retrieved to get it
Const ChunkSize As Long = 10000   '10KB per request
Const OutputFileName As String = "c:\temp\" & MessageID & ".PDF"    'Path of local file


Public Sub Invoke()
'
' Loop until no more data
'
Dim lngReturnedSize As Long
Dim lngStartFrom As Long: lngStartFrom = 0
Dim Chunk() As Byte
Dim Buffer() As Byte

Do While True
    If Not GetChunk(lngStartFrom, Chunk) Then Exit Do
    Buffer = Utils.ConcatByteArrays(Buffer, Chunk)
    lngStartFrom = lngStartFrom + UBound(Chunk) + 1
    'MsgBox "Received so far: " & CStr(lngStartFrom) & " bytes"
Loop

Utils.WriteBinaryFile OutputFileName, Buffer
MsgBox "Saved as " & OutputFileName
End Sub

Private Function GetChunk(ByVal From As Long, ByRef Chunk() As Byte) As Boolean

Dim objEnv As PocketSOAP.CoEnvelope
Dim objHttp As PocketSOAP.HTTPTransport

Set objEnv = New PocketSOAP.CoEnvelope
objEnv.EncodingStyle = ""
objEnv.SetMethod "GetImageChunkEx2", "https://www.interfax.net"
objEnv.SerializerFactory.ElementMapping "buffer", "", "base64Binary", ""
Set objHttp = New PocketSOAP.HTTPTransport
objHttp.SOAPAction = "https://www.interfax.net/GetImageChunkEx2"

objEnv.Parameters.Create "Username", Main.Username, objEnv.URI
objEnv.Parameters.Create "Password", Main.Password, objEnv.URI
objEnv.Parameters.Create "MessageID", MessageID, objEnv.URI
objEnv.Parameters.Create "MarkAsRead", False, objEnv.URI
objEnv.Parameters.Create "ChunkSize", ChunkSize, objEnv.URI
objEnv.Parameters.Create "From", From, objEnv.URI

objHttp.send "https://ws.interfax.net/Inbound.asmx", objEnv.Serialize
objEnv.EncodingStyle = ""
objEnv.parse objHttp

Dim Result As PocketSOAP.CoSoapNode
Set Result = objEnv.Parameters.Item(0)  'entire response

Dim ResultCode As PocketSOAP.CoSoapNode
Set ResultCode = Result.Nodes.itemByName("ResultCode", objEnv.URI)
If CLng(ResultCode.Value)  0 Then
    MsgBox "Bad ResultCode=" & ResultCode.Value
    GetChunk = False
    End
End If

Dim SourceFileType As PocketSOAP.CoSoapNode
Set SourceFileType = Result.Nodes.itemByName("SourceFileType", objEnv.URI)

Dim Buffer As PocketSOAP.CoSoapNode
Set Buffer = Result.Nodes.itemByName("buffer", objEnv.URI)

' Decoding is done at the application level, as PowerSoap does not seem to de-serialize the response.
GetChunk = Utils.DecodeBase64(Buffer.Value, Chunk)

Set objEnv = Nothing
Set objHttp = Nothing

End Function