NTGuru705
asked on
VBScript Byte Array WebService
I am trying to call a webservice which returns a byte array which is a file.... I am trying to do this with vbscript. I can call the webservice no problem the issue is how do I get the contents (which is the actual file) to disk? I can get through the document and locate the contents the question is how do I get it to disk? I have essentially a text string which is an array of bytes and I dont know what to do with it.. in vb.net this is no problem I just dont know how to handle in vbscript.. can anyone help?
ASKER
Well not really... the data isnt text... so I am ot writing a text file...
The webservice is handing me a binary file... and it is handing it to me as a return parameter which is a byte array...
So i .net I can do something like this..
Public Function WriteFile(ByVal ccDocument As Byte(), ByVal FilePath As String) As Integer
Dim objFstream As FileStream
Dim lngLen As Long = ccDocument.Length
Try
objFstream = File.Open(FilePath, FileMode.Create, FileAccess.Write)
objFstream.Write(ccDocumen t, 0, CInt(lngLen))
objFstream.Flush()
objFstream.Close()
Catch ex As Exception
ErrorHandler("WriteFile", ex.Message, AgentName, EventLogEntryType.Error, -5000)
Return -5000
End Try
If Not objFstream Is Nothing Then
objFstream.Close()
objFstream = Nothing
End If
'IF YOU DIDNT ENCOUNTER AN ERROR RETURN 0
Return 0
End Function
How to do this in vbscript though?
The webservice is handing me a binary file... and it is handing it to me as a return parameter which is a byte array...
So i .net I can do something like this..
Public Function WriteFile(ByVal ccDocument As Byte(), ByVal FilePath As String) As Integer
Dim objFstream As FileStream
Dim lngLen As Long = ccDocument.Length
Try
objFstream = File.Open(FilePath, FileMode.Create, FileAccess.Write)
objFstream.Write(ccDocumen
objFstream.Flush()
objFstream.Close()
Catch ex As Exception
ErrorHandler("WriteFile", ex.Message, AgentName, EventLogEntryType.Error, -5000)
Return -5000
End Try
If Not objFstream Is Nothing Then
objFstream.Close()
objFstream = Nothing
End If
'IF YOU DIDNT ENCOUNTER AN ERROR RETURN 0
Return 0
End Function
How to do this in vbscript though?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
right but to write binary data you have to use the wrtie method and the parameter is a byte array which I dont think vbscript supports.
ASKER
Ok I am making progress here...
This is what the XML looks like.. note the content is in the document element...
Problem is when I write it back to disk it isnt right.. anyone recognize the encoding or something? This is just being returned from a vb.net webservice as a byte array.
<ccDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://services.firstfleetinc.com/">
<ccDocGID>1004</ccDocGID>
<Document>DQogImNjX0FkZEF0 dHJpYnV0ZS AiICYgY2NE b2NHSUQgJi AiLCIgJiBj Y0FUeXBlR0 lEICYgIiwn IiAmIGNjQV ZhbHVlICYg Ig0KLS0gUk VUVVJOUyBU SEUgQVZBTF VFR0lEDQoN CnNxbCA9IC JjY19WYWxp ZGF0ZUFWYW x1ZSAiICYg Y2NBVHlwZU dJRCAmICIs JyIgJiBjY0 FWYWx1ZSAm ICInIg0KLS 0gUkVUVVJO UyAxIE9SID AgRk9SIFRS VUUgT1IgRk FMU0U=</Do cument>
- <ccDocProperties>
<ccDocGID>1004</ccDocGID>
<ccDocStatus>1</ccDocStatu s>
<ccDocStatusName>Pending Index</ccDocStatusName>
<ccSorceFileExt>txt</ccSor ceFileExt>
<ccDocTypeGID>1000</ccDocT ypeGID>
<ccDocType>DEFAULT</ccDocT ype>
<ccDocDate>2007-03-26T14:4 4:46.407</ ccDocDate>
<ccDocSize>203</ccDocSize>
<ccDocQueueGID>1000</ccDoc QueueGID>
<ccDocWFName>UNK</ccDocWFN ame>
<ccDocWFGID>0</ccDocWFGID>
<ccDocWFSequence>0</ccDocW FSequence>
<ccDocAdded>2007-03-26T14: 44:46.407< /ccDocAdde d>
<ccDocAuthor>1000</ccDocAu thor>
<ccDocAuthorID>admin</ccDo cAuthorID>
<ccDocEdited>2007-03-26T14 :44:46.407 </ccDocEdi ted>
<ccDocEditor>1000</ccDocEd itor>
<ccDocEditorID>admin</ccDo cEditorID>
<ccDocViewed>2007-03-26T16 :11:24.28< /ccDocView ed>
<ccDocViewer>1000</ccDocVi ewer>
<ccDocViewerID>admin</ccDo cViewerID>
<ccErrorCode>0</ccErrorCod e>
<ccErrorString />
</ccDocProperties>
- <ccDocAttribues>
- <ccDocAttributes>
<ccRowID>3</ccRowID>
<ccATypeGID>1000</ccATypeG ID>
<ccATypeName>DEFAULT</ccAT ypeName>
<ccAValueGID>1</ccAValueGI D>
<ccAValue>Test</ccAValue>
<ccErrorCode>0</ccErrorCod e>
<ccErrorString />
</ccDocAttributes>
- <ccDocAttributes>
<ccRowID>4</ccRowID>
<ccATypeGID>1000</ccATypeG ID>
<ccATypeName>DEFAULT</ccAT ypeName>
<ccAValueGID>2</ccAValueGI D>
<ccAValue>Sivils</ccAValue >
<ccErrorCode>0</ccErrorCod e>
<ccErrorString />
</ccDocAttributes>
</ccDocAttribues>
<ccErrorCode>0</ccErrorCod e>
<ccErrorString />
</ccDocument>
This is what the XML looks like.. note the content is in the document element...
Problem is when I write it back to disk it isnt right.. anyone recognize the encoding or something? This is just being returned from a vb.net webservice as a byte array.
<ccDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://services.firstfleetinc.com/">
<ccDocGID>1004</ccDocGID>
<Document>DQogImNjX0FkZEF0
- <ccDocProperties>
<ccDocGID>1004</ccDocGID>
<ccDocStatus>1</ccDocStatu
<ccDocStatusName>Pending Index</ccDocStatusName>
<ccSorceFileExt>txt</ccSor
<ccDocTypeGID>1000</ccDocT
<ccDocType>DEFAULT</ccDocT
<ccDocDate>2007-03-26T14:4
<ccDocSize>203</ccDocSize>
<ccDocQueueGID>1000</ccDoc
<ccDocWFName>UNK</ccDocWFN
<ccDocWFGID>0</ccDocWFGID>
<ccDocWFSequence>0</ccDocW
<ccDocAdded>2007-03-26T14:
<ccDocAuthor>1000</ccDocAu
<ccDocAuthorID>admin</ccDo
<ccDocEdited>2007-03-26T14
<ccDocEditor>1000</ccDocEd
<ccDocEditorID>admin</ccDo
<ccDocViewed>2007-03-26T16
<ccDocViewer>1000</ccDocVi
<ccDocViewerID>admin</ccDo
<ccErrorCode>0</ccErrorCod
<ccErrorString />
</ccDocProperties>
- <ccDocAttribues>
- <ccDocAttributes>
<ccRowID>3</ccRowID>
<ccATypeGID>1000</ccATypeG
<ccATypeName>DEFAULT</ccAT
<ccAValueGID>1</ccAValueGI
<ccAValue>Test</ccAValue>
<ccErrorCode>0</ccErrorCod
<ccErrorString />
</ccDocAttributes>
- <ccDocAttributes>
<ccRowID>4</ccRowID>
<ccATypeGID>1000</ccATypeG
<ccATypeName>DEFAULT</ccAT
<ccAValueGID>2</ccAValueGI
<ccAValue>Sivils</ccAValue
<ccErrorCode>0</ccErrorCod
<ccErrorString />
</ccDocAttributes>
</ccDocAttribues>
<ccErrorCode>0</ccErrorCod
<ccErrorString />
</ccDocument>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes and there are lots of dlls I have found to help me write this file to disk... thank for your help.. reference link
https://www.experts-exchange.com/questions/22497192/Base64-Binary-Javascript.html
https://www.experts-exchange.com/questions/22497192/Base64-Binary-Javascript.html
You just need to write it to a file?
Use the FSO...
Dim objFSO:Set objFSO=CreateObject("Scrip
Dim objOutput: SetobjOutput=objFSO.Create
objOutput.WriteLine YourData
~sirbounty