How can I deliver images to the client from a web service?

K

Ken Dopierala Jr.

Hi,

I know this post will be considered off-topic. There are a lot of good
coders in these groups and I'm hoping someone can help me out. This is what
I'm working on. I used to use the webservice.htc alot, but now I have to
code for Netscape and Mozilla and it didn't work. This was a good thing,
the webservice.htc would choke if you sent back things like arraylists so I
wrote my own wrapper. No matter what you send (dataset, array, array of
classes, array list, etc.) it'll parse it and let you work with objects
created in javascript. Works great.

Here is the problem. I can't figure out how to dish back images. I have
the browser use XMLHTTP to request an image. I dish it back as a byte array
which I then parse. For the life of me I can't figure out how to change
this byte array into an image using javascript. I've tried everything I can
think of. But the way javascript works you can't just take a valid image in
an array and assign it to a new image object. The var you assign it to just
becomes an array, there is no type conversion that I know of.

With Mozilla I was able to overrun the buffer and then execute code that
would switch an old image with a new one. But I couldn't get it to work
with IE and since this is a total security hack I'm sure it'll be closed
soon for all browsers. I'm able to use javascript to hit a bogus page that
just does a response.write() that delivers the image. But this isn't
elegant because I then need to have the bogus page hit the web service and I
want the client to hit it directly. Anyone have a clue how to do this?

Since I'm on a rant I have another question. Take the XML below as an
example:

<Food>
<Pizza topping="pepperoni">
</Pizza>
</Food>

Parsing this with IE is easy. But in both Netscape and Mozilla the line
breaks are considered children. So while Food really only has one child in
Netscape and Mozilla it appears to have 2 children. The first child is
nothing but a line break, the 2nd child is Pizza. Now logic would tell you
there should at least be 3 then (for the line break between </Pizza> and
</Food>) but there is only two. Pizza also shows to have a child when it
really doesn't. So basically I'm stuck doing the code below. That code
will take any array (even an arraylist) that you return from a web service
and turn it into a javascript object that lets you refer to things by their
actual name. What ticks me off is that for Netscape and Mozilla I have to
test if they are the browser used, if they are I have to like pre-parse it
as you see below. Anyone know any way around this? Thanks for any help!
Ken.

P.S. I use my real email so feel free to spam me for being off topic (I am
doing all this with ASP.Net). But if my Hungarian Notation ticks you
off...spare me the spam and get a life! ;-}


case constArray:
if (flgMoz == false) {
strXML = objOTBReq.responseXML.documentElement;
intNumberOfNodes = strXML.childNodes.length;
}
else {
strXML = objOTBReq.responseXML.documentElement;
flgNotDone = true;
while(flgNotDone) {
flgNotDone = false;
for (intNumberOfElements = 0; intNumberOfElements <
strXML.childNodes.length; intNumberOfElements++) {
if (strXML.childNodes[intNumberOfElements].nodeType == 3) {
strXML.removeChild(strXML.childNodes[intNumberOfElements]);
flgNotDone = true;
break;
}
}
}
intNumberOfNodes = strXML.childNodes.length;
flgNotDone = true;
while(flgNotDone) {
for (intCounter = 0; intCounter < intNumberOfNodes; intCounter++) {
flgNotDone = false;
for (intNumberOfElements = 0; intNumberOfElements <
strXML.childNodes[intCounter].childNodes.length; intNumberOfElements++) {
if
((strXML.childNodes[intCounter].childNodes[intNumberOfElements].nodeType ==
3) &&
(strXML.childNodes[intCounter].childNodes[intNumberOfElements].nodeValue ==
"")) {

strXML.childNodes[intCounter].removeChild(strXML.childNodes[intCounter].chil
dNodes[intNumberOfElements]);
flgNotDone = true;
}
}
}
}
}
strNodeName = strXML.nodeName;
if (strNodeName.indexOf("anyType") != -1) {
intNumberOfNodes -= 1;
}
ReturnValue.Value = new Array();
objReturnValue = new Object();
for (intElementCounter = 0; intElementCounter <
strXML.childNodes[0].childNodes.length; intElementCounter++) {
if
(strXML.childNodes[0].childNodes[intElementCounter].childNodes.length != 0)
{
if (strXML.childNodes[0].childNodes[intElementCounter].firstChild
== null) {
eval("objReturnValue." +
strXML.childNodes[0].childNodes[intElementCounter].nodeName + " = '';");
}
else {
eval("objReturnValue." +
strXML.childNodes[0].childNodes[intElementCounter].nodeName + " =
strXML.childNodes[0].childNodes[intElementCounter].firstChild.nodeValue;");
}
}
else {
eval("objReturnValue.Value =
strXML.childNodes[0].childNodes[intElementCounter].nodeValue;");
}
}
ReturnValue.Value[0] = objReturnValue;
for (intNodeCounter = 1; intNodeCounter < intNumberOfNodes;
intNodeCounter++) {
objReturnValue = new Object();
for (intElementCounter = 0; intElementCounter <
strXML.childNodes[intNodeCounter].childNodes.length; intElementCounter++) {
if
(strXML.childNodes[intNodeCounter].childNodes[intElementCounter].childNodes.
length != 0) {
if
(strXML.childNodes[intNodeCounter].childNodes[intElementCounter].firstChild
== null) {
eval("objReturnValue." +
strXML.childNodes[intNodeCounter].childNodes[intElementCounter].nodeName + "
= '';");
}
else {
eval("objReturnValue." +
strXML.childNodes[intNodeCounter].childNodes[intElementCounter].nodeName + "
= strXML.childNodes[intNodeCounter].childNodes[intElementCounter].firstChild
..nodeValue;");
}
}
else {
eval("objReturnValue.Value =
strXML.childNodes[intNodeCounter].childNodes[intElementCounter].nodeValue;")
;
}
}
ReturnValue.Value[intNodeCounter] = objReturnValue;
}
break;
 

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,776
Messages
2,569,603
Members
45,197
Latest member
ScottChare

Latest Threads

Top