【发布时间】:2010-08-27 11:50:48
【问题描述】:
我一直在创建一个新服务来将大文件下载到客户端。我想在 Windows 服务中托管服务。 在服务中我正在写作:
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;
}
}
界面如下:
[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;
}
}
}
当我调用该服务时,它显示“基础连接已关闭”。 你可以得到实施 http://cid-bafa39a62a57009c.office.live.com/self.aspx/.Public/MicaUpdaterService.zip 请帮帮我。
【问题讨论】:
标签: c# .net windows wcf web-services