Response.BinaryWrite question, please

Discussion in 'ASP .Net' started by Alex Nitulescu, Feb 15, 2005.

  1. 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 ?
    Alex Nitulescu, Feb 15, 2005
    #1
    1. Advertising

  2. 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

    "Alex Nitulescu" <> wrote in message
    news:...
    > 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 ?
    >
    >
    William F. Robertson, Jr., Feb 15, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DAC
    Replies:
    1
    Views:
    1,847
    Steve C. Orr, MCSD
    Jul 31, 2003
  2. =?Utf-8?B?QnJhZCBSb2JlcnRz?=

    RE: Response.BinaryWrite or something causes multiple posts

    =?Utf-8?B?QnJhZCBSb2JlcnRz?=, Aug 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    554
    =?Utf-8?B?RGFuIEM=?=
    Aug 19, 2004
  3. spmm#

    Response.BinaryWrite question

    spmm#, Nov 3, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    9,524
    rdevalco
    Mar 23, 2013
  4. Thomas Satzinger

    Response.BinaryWrite question

    Thomas Satzinger, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    381
    Thomas Satzinger
    Jun 12, 2005
  5. Replies:
    1
    Views:
    829
Loading...

Share This Page