title: Large File download in WCF and Windows Service
body: <p>I have been creating a new service to download large file to client. I want to host the service in a Windows Service. 
  In service I am writing :</p>
  
  <pre><code> public class FileTransferService : IFileTransferService
      {
          private string ConfigPath
          {
              get
              {
                  return ConfigurationSettings.AppSettings["DownloadPath"];
              }
          }
          private FileStream GetFileStream(string file)
          {
  
              string filePath = Path.Combine(this.ConfigPath, file);
              FileInfo fileInfo = new FileInfo(filePath);
  
              if (!fileInfo.Exists)
                  throw new FileNotFoundException("File not found", file);
  
              return new FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
          }
  
          public RemoteFileInfo DownloadFile(DownloadRequest request)
          {
              FileStream stream = this.GetFileStream(request.FileName);
  
              RemoteFileInfo result = new RemoteFileInfo();
              result.FileName = request.FileName;
              result.Length = stream.Length;
              result.FileByteStream = stream;
              return result;
          }
      }
  </code></pre>
  
  <p>The Interface looks like :</p>
  
  <pre><code> [ServiceContract]
      public interface IFileTransferService
      {
          [OperationContract]
          RemoteFileInfo DownloadFile(DownloadRequest request);
      }
      [DataContract]
      public class DownloadRequest
      {
          [DataMember]
          public string FileName;
      }
  
      [DataContract]
      public class RemoteFileInfo : IDisposable
      {
          [DataMember]
          public string FileName;
  
          [DataMember]
          public long Length;
  
          [DataMember]
          public System.IO.Stream FileByteStream;
  
          public void Dispose()
          {
              if (FileByteStream != null)
              {
                  FileByteStream.Close();
                  FileByteStream = null;
              }
          }
      }
  </code></pre>
  
  <p>When I am calling the service it says "Underlying connection was closed."
  You can get the implementation 
  <a href="http://cid-bafa39a62a57009c.office.live.com/self.aspx/.Public/MicaUpdaterService.zip" rel="nofollow noreferrer">http://cid-bafa39a62a57009c.office.live.com/self.aspx/.Public/MicaUpdaterService.zip</a>
   Please help me.</p>