我正在編寫一個控制客戶端下載的應用程序,我需要知道什麼時候下載成功,但我需要在服務器端做,但是我沒有找到像這樣的東西。WCF下載文件控制
這是我的服務器代碼:
public GetCoverResponse GetCover(GetCoverRequest request)
{
return new GetCoverResponse()
{
Cover = downloadsManagementService.GetCover(request.IssueId)
};
}
[MessageContract]
public class GetCoverResponse: IDisposable
{
[MessageBodyMember(Order=1)]
public Stream Cover;
public void Dispose()
{
if (Cover != null)
{
Cover.Close();
Cover = null;
}
}
}
GetCover返回流。 我使用這個配置:
<basicHttpBinding>
<binding name="StreamedBindingConfiguration" messageEncoding="Mtom" maxBufferSize="65536"
transferMode="Streamed">
</binding>
</basicHttpBinding>
客戶端代碼是:
static void Main(string[] args)
{
var client = new DownloadsService.DownloadsServiceClient();
var data = client.GetCover(1);
FileStream f = new FileStream(@"D:\copiaDDDDDDD.txt", FileMode.OpenOrCreate);
Copy(data, f);
f.Close();
data.Close();
client.Close();
}
public static void Copy(Stream source, Stream target)
{
byte[] buffer = new byte[65536];
int bytes;
try
{
while ((bytes = source.Read(buffer, 0, buffer.Length)) > 0)
{
target.Write(buffer, 0, bytes);
}
}
finally
{
target.Flush();
}
}
我需要知道當一個客戶端下載成功後不會再次調用該服務。
你可以發佈一些代碼顯示如何下載文件? – Tridus 2011-02-01 02:08:27