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 :
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;
}
}
The Interface looks like :
[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;
}
}
}
When I am calling the service it says "Underlying connection was closed." You can get the implementation http://cid-bafa39a62a57009c.office.live.com/self.aspx/.Public/MicaUpdaterService.zip Please help me.