XML Webservice Binary File load

J

jdhavo

I'm trying to download an image file using XML from a web service.
When the dialog box appears asking if I want to save the document or
open it, If I click save and then open it, it works fine. If I click
open, I get an error that the header is not recognized. Node 3
contains the binary document returned from the Doc_Qanda_rev.exe.
Here is my code:
ASPX Module:
sXML = pdmWS.GetBinaryDoc(ErrorCode, ErrorMsg,
e.Item.Cells(5).Text.Trim, e.CommandArgument.ToString.Trim, "")
doc.LoadXml(sXML)
MrNode = doc.SelectSingleNode("/GetBinaryDocReply/DOC")
binaryFile =
Convert.FromBase64String(MrNode.ChildNodes.Item(3).InnerText.ToString)
Response.ContentType = "image/tiff"
Response.AddHeader("Content-Length", binaryFile.Length)
Response.AddHeader("Content-Disposition", "attachment;
filename=" & "testjeff.tif")
Response.AddHeader("Content-Type", "image/tiff")
Response.BinaryWrite(binaryFile)
Response.Flush()
Response.End()

WebService Code:(pdmWS.GetBinaryDoc)
URL = String.Concat("http://", URL, "/doc_qanda_rev.exe?",
docnum.Trim, ",1,", revNum)
Dim myHttpWebReq As HttpWebRequest =
CType(WebRequest.Create(URL), System.Net.HttpWebRequest)
myHttpWebReq.Timeout = 15000
myHttpWebReq.Method = "GET"
Dim myHttpWebResp As HttpWebResponse =
CType(myHttpWebReq.GetResponse(), System.Net.HttpWebResponse)
Dim br As BinaryReader = New
BinaryReader(myHttpWebResp.GetResponseStream)
binaryFile = br.ReadBytes(4096)
While binaryFile.Length > 0
ms.Write(binaryFile, 0, binaryFile.Length)
binaryFile = br.ReadBytes(4096)
End While
myHttpWebResp.Close()
sXML = "<GetBinaryDocReply>"
sXML = String.Concat(sXML, "<DOC>")
sXML = String.Concat(sXML, "<CONTENTTYPE>", contentType,
"</CONTENTTYPE>")
sXML = String.Concat(sXML, "<FILENAME>", handle.Trim,
"</FILENAME>")
sXML = String.Concat(sXML, "<FILELEN>", binaryFile.Length,
"</FILELEN>")
sXML = String.Concat(sXML, "<FILECONT>",
Convert.ToBase64String(binaryFile), "</FILECONT>")
sXML = String.Concat(sXML, "</DOC>",
"</GetBinaryDocReply>")

The Save Document option works fine but the Image Editory throws an
error. Tried several image editors and the same error is returned.

Thanks in advance
Clem
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top