locked
ADO .NET Data Service - Reading EDM.Binary Type RRS feed

  • Question

  • Hi, I am just starting with ADO .NET Data services and am trying to query Northwnd database Categories table. The solution is working good. However, when I try to retrieve the Picture (which is a System.Byte()) and convert it to an image, the image does not show. How do I achieve this? here is the code I am using

    Dim myURI As String = "http://localhost:50105/WebSite3/NorthwndService.svc"

    Dim myService As New NORTHWNDEntities(New Uri(myURI))

    Dim q = myService.Execute(Of Categories)(New Uri("/Products(1)/Categories/Picture", UriKind.Relative))

    Response.Clear()

    Response.ContentType = "image/jpeg"

    Dim myStream As New IO.MemoryStream(q(0).Picture, 0, q(0).Picture.Length)

    myStream.Write(q(0).Picture, 0, q(0).Picture.Length)

    Dim myImage As Drawing.Image = Drawing.Image.FromStream(myStream)

    myImage.Save(Response.OutputStream, Drawing.Imaging.ImageFormat.Jpeg)

     
    Using this, nothing is being returned. How do I convert the Picture element in Categories Table into an image? I have tried some variations on the above code, such as calling the extension method single() in the query as well as using response.binarywrite(). But nothing is being returned. The error message I get is:

    Error processing response stream. Mixed content is not supported. The structured type being evaluated is 'System.Byte[]'.

    Exception Details: System.InvalidOperationException: Error processing response stream. Mixed content is not supported. The structured type being evaluated is 'System.Byte[]'.


    Can someone please help me out? Thanks in advance.
    Monday, December 15, 2008 10:05 PM

All replies

  • Here's some code in C# that works with Silverlight client.  The Song type has binary properties for a picture and an audio file.

    void CallbackGetData(IAsyncResult result)

    {

    DataServiceQuery<Song> queryResult = (DataServiceQuery<Song>)result.AsyncState;

    IEnumerable<Song> resultSongs = queryResult.EndExecute(result);

    Song firstSong = resultSongs.First<Song>();

    string lyrics = firstSong.Lyrics;

    this.textBoxLyrics.Text = lyrics;

    MemoryStream stream = new MemoryStream(firstSong.Picture, 0, firstSong.Picture.Length, false);

    System.Windows.Media.Imaging.BitmapImage bitImage =
                                                    new System.Windows.Media.Imaging.BitmapImage();

    bitImage.SetSource(stream);

    image1.Source = bitImage;

    MemoryStream streamMedia = new MemoryStream(firstSong.Audio, 0, firstSong.Audio.Length, false);

    mediaElement1.SetSource(streamMedia);

    }


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Saturday, January 17, 2009 10:06 PM