lsindhu
September 15th, 2005, 06:45 PM
Hi,
I am running into some issues while streaming a TIF image from a Vb6 app to a .Net webservice.
The probelm is that I seem to be losing some bytes. The source tif image is 22,974 bytes and the destination tif image is only 22,450 bytes. I have tried different encoders to see if it will make a difference and have not been successful. Any help would be greatly appreciated.
Here is the vb6 code.
Dim objStream As New ADODB.Stream
Dim objXmlDoc As New MSXML2.DOMDocument30
Dim objDocElem As MSXML2.IXMLDOMElement
Dim CHUNK As Long
Dim strBase64 As String
Dim intBlocks As Integer
Dim intNumberOfBlocks As Integer
Dim lSize As Long
Dim strWebServiceURL As String
Dim strReturn As String
Dim xmlDomDoc As New DOMDocument
Dim strMsg As String
Dim objHTTPGet As New MSXML2.XMLHTTP40
Dim intleft As Integer
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile gstrbatchscandir & strTiffName(i)
lSize = objStream.SIZE
CHUNK = 1024
intNumberOfBlocks = (lSize - (lSize Mod CHUNK)) / CHUNK
intleft = lSize Mod CHUNK
intNumberOfBlocks = (lSize - (lSize Mod CHUNK)) / CHUNK
If intleft > 0 Then
intNumberOfBlocks = intNumberOfBlocks + 1
End If
For intBlocks = 1 To intNumberOfBlocks
Set objDocElem = objXmlDoc.createElement("b64")
objDocElem.dataType = "bin.base64"
If intleft > 0 And intBlocks = intNumberOfBlocks Then
objDocElem.nodeTypedValue = objStream.Read(intleft)
Else
objDocElem.nodeTypedValue = objStream.Read(CHUNK)
End If
strBase64 = objDocElem.Text
strWebServiceURL = "http://" & gstrImagingMTSServer & "/filereciever/FileReciever.asmx/RecievesFileNoMD5?strFileName= " & strTiffName(i) & " &strBlock= " & strBase64 & "&intCurrentBlock= " & intBlocks & " &intTotalBlocks= " & intNumberOfBlocks & ""
strMsg = "1.0.1"
objHTTPGet.Open "GET", strWebServiceURL, False
strMsg = "1.0.2"
objHTTPGet.send
strMsg = "1.0.3"
xmlDomDoc.loadXML (objHTTPGet.responseText)
strReturn = xmlDomDoc.getElementsByTagName("string").Item(0).Text
If strReturn = False Then
MsgBox objHTTPGet.responseText
End If
Next
Here is the webservice code
WebMethod(Description:=" Recieves Files without MD5 ecryption.", MessageName:="RecievesFileNoMD5")> _
Public Function RecieveFile(ByVal strFileName As String, ByVal strBlock As String, ByVal intCurrentBlock As Int32, ByVal intTotalBlocks As Int32) As String
Dim file As System.IO.File
Dim strWorkingDir As String
Dim strDestination As String
Dim strOutputDirectory As String
Dim strDecodedBlock As String
Dim strMsg As String
Dim decodedBlock() As Byte
Dim strFile As String
Dim byteMD5HashCode() As Byte
Dim byteMd5 As Byte
Dim myLocalFile As System.io.FileStream
Dim base64block() As Byte
Dim strTempFile As String
Dim WorkingDir As Directory
Dim strTime As String
Dim bDebug As Boolean
Dim adostream1 As New ADODB.Stream
On Error GoTo HANDLE
strWorkingDir = Common.GetRegistryValue(Microsoft.Win32.RegistryHive.LocalMachine, Common.EWW_IMAGING_FILERECIEVER, "WorkingDir", "C:\Temp\")
strOutputDirectory = Common.GetRegistryValue(Microsoft.Win32.RegistryHive.LocalMachine, Common.EWW_IMAGING_FILERECIEVER, "OutPutDir", "C:\imagecache\outbound\SendNow\")
bDebug = UCase(Common.GetRegistryValue(Microsoft.Win32.RegistryHive.LocalMachine, Common.EWW_IMAGING_FILERECIEVER, "Debug", "FALSE"))
If strWorkingDir = "" Then
RecieveFile = False
strMsg = "RecieveFile:Unable to get temporary file path " & strWorkingDir
GoTo HANDLE
End If
strTempFile = strWorkingDir & strFileName & ".D"
strFile = strWorkingDir & strFileName
If intCurrentBlock = 1 Then
If file.Exists(strFile) = True Then
file.Delete(strFile)
End If
If file.Exists(strTempFile) = True Then
file.Delete(strTempFile)
End If
End If
Dim objXML As MSXML2.DOMDocument30
Dim objNode As MSXML2.IXMLDOMElement
Dim decode As Byte()
Dim strDecode As String
objXML = New MSXML2.DOMDocument
objNode = objXML.createElement("b64")
objNode.dataType = "bin.base64"
objNode.text = strBlock
strDecode = System.Text.Encoding.Default.GetString(decode)
Dim streamwriter1 As New StreamWriter(strTempFile, True, System.Text.Encoding.Default)
streamwriter1.Write(strDecode)
streamwriter1.Close()
If intCurrentBlock = intTotalBlocks Then
If strOutputDirectory = "" Then
RecieveFile = False
strMsg = "RecieveFile:Unable to get Output Directory path " & strOutputDirectory
GoTo HANDLE
End If
strDestination = strOutputDirectory & strFileName
If file.Exists(strDestination) = False Then
file.Move(strFile, strDestination)
Else
If WorkingDir.Exists(strOutputDirectory & "Duplicate") = False Then
WorkingDir.CreateDirectory(strOutputDirectory & "Duplicate")
End If
strDestination = strOutputDirectory & "Duplicate\" & strFileName
If file.Exists(strDestination) = True Then
strTime = Replace((Replace(Now(), "/", "")), " ", "")
strTime = Replace(strTime, ":", "")
strDestination = strDestination & strTime
End If
file.Move(strFile, strDestination)
End If
If file.Exists(strTempFile) = True Then
file.Delete(strTempFile)
End If
Else
RecieveFile = True
'WriteToEventLog(strBlock, "FileReciever", EventLogEntryType.Warning)
End If
Exit Function
HANDLE:
RecieveFile = False & strMsg & Err.Number & Err.Description
Debug.Write(Err.Number & Err.Description)
WriteToEventLog(strMsg & Err.Number & Err.Description, "FileReciever", EventLogEntryType.Warning)
If bDebug = False Then
If file.Exists(strFile) = True Then
file.Delete(strFile)
End If
If file.Exists(strTempFile) = True Then
file.Delete(strTempFile)
End If
End If
file = Nothing
streamwriter1 = Nothing
Exit Function
End Function
I am running into some issues while streaming a TIF image from a Vb6 app to a .Net webservice.
The probelm is that I seem to be losing some bytes. The source tif image is 22,974 bytes and the destination tif image is only 22,450 bytes. I have tried different encoders to see if it will make a difference and have not been successful. Any help would be greatly appreciated.
Here is the vb6 code.
Dim objStream As New ADODB.Stream
Dim objXmlDoc As New MSXML2.DOMDocument30
Dim objDocElem As MSXML2.IXMLDOMElement
Dim CHUNK As Long
Dim strBase64 As String
Dim intBlocks As Integer
Dim intNumberOfBlocks As Integer
Dim lSize As Long
Dim strWebServiceURL As String
Dim strReturn As String
Dim xmlDomDoc As New DOMDocument
Dim strMsg As String
Dim objHTTPGet As New MSXML2.XMLHTTP40
Dim intleft As Integer
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile gstrbatchscandir & strTiffName(i)
lSize = objStream.SIZE
CHUNK = 1024
intNumberOfBlocks = (lSize - (lSize Mod CHUNK)) / CHUNK
intleft = lSize Mod CHUNK
intNumberOfBlocks = (lSize - (lSize Mod CHUNK)) / CHUNK
If intleft > 0 Then
intNumberOfBlocks = intNumberOfBlocks + 1
End If
For intBlocks = 1 To intNumberOfBlocks
Set objDocElem = objXmlDoc.createElement("b64")
objDocElem.dataType = "bin.base64"
If intleft > 0 And intBlocks = intNumberOfBlocks Then
objDocElem.nodeTypedValue = objStream.Read(intleft)
Else
objDocElem.nodeTypedValue = objStream.Read(CHUNK)
End If
strBase64 = objDocElem.Text
strWebServiceURL = "http://" & gstrImagingMTSServer & "/filereciever/FileReciever.asmx/RecievesFileNoMD5?strFileName= " & strTiffName(i) & " &strBlock= " & strBase64 & "&intCurrentBlock= " & intBlocks & " &intTotalBlocks= " & intNumberOfBlocks & ""
strMsg = "1.0.1"
objHTTPGet.Open "GET", strWebServiceURL, False
strMsg = "1.0.2"
objHTTPGet.send
strMsg = "1.0.3"
xmlDomDoc.loadXML (objHTTPGet.responseText)
strReturn = xmlDomDoc.getElementsByTagName("string").Item(0).Text
If strReturn = False Then
MsgBox objHTTPGet.responseText
End If
Next
Here is the webservice code
WebMethod(Description:=" Recieves Files without MD5 ecryption.", MessageName:="RecievesFileNoMD5")> _
Public Function RecieveFile(ByVal strFileName As String, ByVal strBlock As String, ByVal intCurrentBlock As Int32, ByVal intTotalBlocks As Int32) As String
Dim file As System.IO.File
Dim strWorkingDir As String
Dim strDestination As String
Dim strOutputDirectory As String
Dim strDecodedBlock As String
Dim strMsg As String
Dim decodedBlock() As Byte
Dim strFile As String
Dim byteMD5HashCode() As Byte
Dim byteMd5 As Byte
Dim myLocalFile As System.io.FileStream
Dim base64block() As Byte
Dim strTempFile As String
Dim WorkingDir As Directory
Dim strTime As String
Dim bDebug As Boolean
Dim adostream1 As New ADODB.Stream
On Error GoTo HANDLE
strWorkingDir = Common.GetRegistryValue(Microsoft.Win32.RegistryHive.LocalMachine, Common.EWW_IMAGING_FILERECIEVER, "WorkingDir", "C:\Temp\")
strOutputDirectory = Common.GetRegistryValue(Microsoft.Win32.RegistryHive.LocalMachine, Common.EWW_IMAGING_FILERECIEVER, "OutPutDir", "C:\imagecache\outbound\SendNow\")
bDebug = UCase(Common.GetRegistryValue(Microsoft.Win32.RegistryHive.LocalMachine, Common.EWW_IMAGING_FILERECIEVER, "Debug", "FALSE"))
If strWorkingDir = "" Then
RecieveFile = False
strMsg = "RecieveFile:Unable to get temporary file path " & strWorkingDir
GoTo HANDLE
End If
strTempFile = strWorkingDir & strFileName & ".D"
strFile = strWorkingDir & strFileName
If intCurrentBlock = 1 Then
If file.Exists(strFile) = True Then
file.Delete(strFile)
End If
If file.Exists(strTempFile) = True Then
file.Delete(strTempFile)
End If
End If
Dim objXML As MSXML2.DOMDocument30
Dim objNode As MSXML2.IXMLDOMElement
Dim decode As Byte()
Dim strDecode As String
objXML = New MSXML2.DOMDocument
objNode = objXML.createElement("b64")
objNode.dataType = "bin.base64"
objNode.text = strBlock
strDecode = System.Text.Encoding.Default.GetString(decode)
Dim streamwriter1 As New StreamWriter(strTempFile, True, System.Text.Encoding.Default)
streamwriter1.Write(strDecode)
streamwriter1.Close()
If intCurrentBlock = intTotalBlocks Then
If strOutputDirectory = "" Then
RecieveFile = False
strMsg = "RecieveFile:Unable to get Output Directory path " & strOutputDirectory
GoTo HANDLE
End If
strDestination = strOutputDirectory & strFileName
If file.Exists(strDestination) = False Then
file.Move(strFile, strDestination)
Else
If WorkingDir.Exists(strOutputDirectory & "Duplicate") = False Then
WorkingDir.CreateDirectory(strOutputDirectory & "Duplicate")
End If
strDestination = strOutputDirectory & "Duplicate\" & strFileName
If file.Exists(strDestination) = True Then
strTime = Replace((Replace(Now(), "/", "")), " ", "")
strTime = Replace(strTime, ":", "")
strDestination = strDestination & strTime
End If
file.Move(strFile, strDestination)
End If
If file.Exists(strTempFile) = True Then
file.Delete(strTempFile)
End If
Else
RecieveFile = True
'WriteToEventLog(strBlock, "FileReciever", EventLogEntryType.Warning)
End If
Exit Function
HANDLE:
RecieveFile = False & strMsg & Err.Number & Err.Description
Debug.Write(Err.Number & Err.Description)
WriteToEventLog(strMsg & Err.Number & Err.Description, "FileReciever", EventLogEntryType.Warning)
If bDebug = False Then
If file.Exists(strFile) = True Then
file.Delete(strFile)
End If
If file.Exists(strTempFile) = True Then
file.Delete(strTempFile)
End If
End If
file = Nothing
streamwriter1 = Nothing
Exit Function
End Function