title: WCF Streaming - who closes the file?
body: <p>According to Microsoft's samples, here's how one would go about streaming a file throuhg WCF:</p>
  
  <pre><code>   // 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 
              //(e.g. 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;
              }
          }
  ...
  </code></pre>
  
  <p>Now, how do I know who's responsible for releasing the FileStream when the transfer is done?</p>
  
  <p>EDIT: If the code is put inside a "using" block the stream gets shut down before the client receives anything.</p>