According to Microsoft samples, here's how to translate the WCF throuhg file:
// Service class which implements the service contract public class StreamingService : IStreamingSample { public System.IO.Stream GetStream(string data) { //this file path assumes the image is in // the Service folder and the service is executing // in service/bin string filePath = Path.Combine( System.Environment.CurrentDirectory, ".\\image.jpg"); //open the file, this could throw an exception //(eg if the file is not found) //having includeExceptionDetailInFaults="True" in config // would cause this exception to be returned to the client try { FileStream imageFile = File.OpenRead(filePath); return imageFile; } catch (IOException ex) { Console.WriteLine( String.Format("An exception was thrown while trying to open file {0}", filePath)); Console.WriteLine("Exception is: "); Console.WriteLine(ex.ToString()); throw ex; } } ...
Now, how do I know who is responsible for releasing FileStream when the transfer is complete?
EDIT: if the code is placed inside the "using" block, the thread is disconnected before the client receives anything.
source share