Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi good folks,
I am trying to open a file and read the data using Silverlight where the file/Stream is effectively opened via a WCF class that encapsulates a stream.

When I attempt to implement what is described above the Async event handier return parameter, e.Result returns a Byte[] rather than a Stream, why ?

Below is what I have implemented:

namespace SilverlightApplication1.Web
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        Stream GetAStream( );
    }
}


The implemented class:

SQL
public class Service1 : IService1
    {
        public Stream GetAStream( )
        {
            return new FileStream( @"C:\temp\hello.txt", FileMode.Open );
        }
    }



On the Silverlight client side when I add the WCF service reference I add the GetAStream call as shown below.

C#
public partial class MainPage : UserControl
    {
        public MainPage( )
        {
            InitializeComponent();

            ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client();
            sc.GetAStreamCompleted +=new EventHandler.ServiceReference1.GetAStreamCompletedEventArgs(sc_GetAStreamCompleted);
        }

        public void sc_GetAStreamCompleted (object sender, ServiceReference1.GetAStreamCompletedEventArgs e)
        {

           Byte[] bytes = e.Result;
// I was hoping the result would be something like Stream xyz = e.Result ???
}
Posted
Updated 4-Nov-12 18:57pm
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900