tags:

views:

33

answers:

2

I have the following:

Public Interface INorthwindSvc

<OperationContract()>
<WebGet(UriTemplate:="EmployeePictureBytes?id={EmpId}")>
Function GetEmployeePictureBytesById(ByVal EmpId As String) As Byte()

End Interface

I got the method implemented (using EF 4.0) as follows:

Public Function GetEmployeePictureBytesById(ByVal EmpId As String) As Byte() Implements INorthwindSvc.GetEmployeePictureBytesById
    Dim ctxt As New NorthwindEntities
    Dim q = From c In ctxt.Employees
            Where c.EmployeeID = EmpId
            Select c.Photo

    Return q.FirstOrDefault
End Function

I am able to receive bytes when I access the operation from browser. If I try to access the same using Win Client as follows (an error occurs as shown inline):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim o As New WebClient
    Dim b() As Byte = o.DownloadData(New Uri("http://localhost:8732/WcfWebHttpSvcLib/rest/EmployeePictureBytes?id=2"))

    Dim ms As New MemoryStream()
    ms.Write(b, 0, b.Length)

    Dim original As New System.Drawing.Bitmap(ms) 'error: parameter is not valid

End Sub

I also tried the same using Image.FromStream. But, still no luck.

Can anyone help me on this?

thanks

A: 

You're not rewinding the memorystream after writing to it, so trying to read from it will fail That said, even that's unnecessary, as you could just write:

im ms As New MemoryStream(b)
' now call FromStream
tomasr
A: 

I tried originally with the same code as you asked. But, no luck.