0

我有以下内容:

公共接口 INorthwindSvc

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

端接口

我实现的方法(使用 EF 4.0)如下:

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

当我从浏览器访问操作时,我能够接收字节。如果我尝试使用 Win Client 访问相同的内容,如下所示(发生错误,如内联所示):

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

我也尝试使用 Image.FromStream 进行相同的操作。但是,仍然没有运气。

谁可以帮我这个事?

谢谢

4

1 回答 1

0

写入内存流后,您不会倒带,因此尝试从中读取将失败也就是说,即使这样也没有必要,因为您可以只写:

im ms As New MemoryStream(b)
' now call FromStream
于 2010-07-07T13:00:49.647 回答