Response.BinaryWrite question, please

A

Alex Nitulescu

Hi. I have a WebService which provides a webmethod which returns a byte
array representing a picture. The method's signature is:

<WebMethod(Description:="Shows something nice every time !")> Public
Function GetRandomImage() As Byte()

I then have a test application (with a web reference to my web service)
which has the following code:

Public Class BinaryWebServiceTest
Inherits System.Web.UI.Page
Protected WithEvents lblResults As System.Web.UI.WebControls.Label

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim objBinaryWebService As New localhost.ImagesWebService()

Response.Clear()
Response.ClearHeaders()
Response.ContentType = "image/jpeg"
Response.BinaryWrite(objBinaryWebService.GetRandomImage)
objBinaryWebService.Dispose()
End Sub
End Class

That's all, and it works fine, except.... I have controls on my test form. I
also have set a bgColor of my page, a custom header, footer, and so on.
However, when I call "response.BinaryWrite" they all vanish (or is it
because of "Response.ContentType" ???) - the random pictures I'm showing
look just fine, but I need to paint them differently, so as to be able to
see the rest of the contents of my page. What are my options, please ?

Thank you, Alex.

PS. Yes, I *could* use a Image control and in the web service manufacture a
random NavigateURL from my "Pictures" directory, but what If I need to
transmit images instead of links ?
 
W

William F. Robertson, Jr.

You options are to use a http handler and have the handler make the
connection to your webservice. You can not encode more than one content
type in an html page. When this page is loading, you are changing the
content type to image, and then sending the binary data for this one image.
The browser is simply ignoring the rest of it.

http://msdn.microsoft.com/msdnmag/issues/04/04/CuttingEdge/default.aspx

You will use a http handler for the image. The resulting html will look
something like <img src="imageHandler.axd">

HTH,

bill
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top