Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Returning a byte array with a web service


Message #1 by Jay Fields <JFields@c...> on Wed, 25 Sep 2002 10:33:22 -0400
To return a byte array, you should use 'Return stream.GetBuffer()' instead 
of 'Return stream.ToArray'.



Similar Threads in p2p.wrox.com - vb_dotnet
Can a WebService method accept a stream as a parameter?
http://p2p.wrox.com/archive/vb_dotnet/2002-06/26.asp

Passing a binary image file thru a web service
http://p2p.wrox.com/archive/vb_dotnet/2002-06/40.asp



Previous message: 
> I want to use a web service to return a byte array that will be the 
bytes of
a picture.  I got the function below from the Professional Web Services
book, but it doesn't seem to work no matter what file I give it.  I have a
picture at c:, the localhost, a virtual directory, but no matter if I pass
it "c:\pic.jpg","http://localhost/pic.jpg", or "/pictures/pic.jpg" I always
get Nothing in return.  What am I missing?


    <WebMethod()> Public Function getImage(ByVal fname As String) As Byte()
        Dim myBitmap As System.Drawing.Bitmap
        Dim stream As System.IO.MemoryStream

        stream = New System.IO.MemoryStream()
        Try
            myBitmap = New System.Drawing.Bitmap(fname)
            myBitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg)
            Return stream.ToArray
        Catch e As Exception
            Return Nothing
        End Try
    End Function

  Return to Index