473,386 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

XML Webservice Binary File load

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

Feb 23 '06 #1
1 1787
I cant answer yuor question, but I can direct you to a possible solution, a
possible alternative at least.

http://www.codeproject.com/soap/MTOMWebServices.asp

--
Regards

John Timney
Microsoft MVP

<jd****@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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

Feb 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: knapak | last post by:
Hello I'm a self instructed amateur attempting to read a huge file from disk... so bear with me please... I just learned that reading a file in binary is faster than text. So I wrote the...
2
by: author | last post by:
Newbie Q... When I hit the "ws.asmx" in a browser, I get "Parser Error Message: Could not create type 'Service1'" ?? If I use the file "ws_ok.asmx" (without codebehind, but same code), I get...
11
by: Andy | last post by:
Make the story short, I have a VB.NET client interface calling .NET webservice, written in VB.NET as well. I am trying to make the client as thin as possible so I let the webservice part to...
5
by: BobAchgill | last post by:
Can you point me to a simple example of how to transfer a file (send or receive) using a webservice. Thanks! Bob PS. Pardon my double posting. I also posted to the webservices forum.
8
by: Topper | last post by:
Hello. I have simple web folders structure: -ROOT - BIN WebService.dll WebService.asmx I need to use my WebService.dll not in bin folder - for example, in ROOT. How do i this? How can i do...
3
by: Pebble | last post by:
Hi folks, I have a WebService that simply acts as a thin wrapper to a .Net dll. Literally almost zero code in the WebService. Parameters passed to the WebService are simply used as...
15
by: JoeC | last post by:
I am writing a program that I am trying to learn and save binary files. This is the page I found as a source: http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html I have...
5
by: Allan Ebdrup | last post by:
I have a webservice in ASP.Net 2.0, I need to store and load a xml configuration file in relation to one of the web methods in my webservice. What's the best place to store and the best way to load...
2
by: ksheerasagar17 | last post by:
Hello All, Scenario: Sending an image through webservice as byte array to an Java webservice. The Problem1: The webservice method image property expects (data type) SByte rather than Byte...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.