开发者

WCF download file control

开发者 https://www.devze.com 2023-02-07 15:02 出处:网络
I\'m writing an application that controls the client downloads, Ineed know when a download is successful, but I need do it in the server side, but idon\'t find something like this.

I'm writing an application that controls the client downloads, I need know when a download is successful, but I need do it in the server side, but i don't find something like this.

This is my Server code:

    public GetCoverResponse GetCover(GetCoverRequest request)
    {
        return new GetCoverResponse()
        {
            Cover = downloadsManagementService.GetCover(request.IssueId)
        };
    }

[MessageContract]
public class GetCoverResp开发者_如何学JAVAonse: IDisposable
{
    [MessageBodyMember(Order=1)]
    public Stream Cover;

    public void Dispose()
    {
        if (Cover != null)
        {
            Cover.Close();
            Cover = null;
        }
    }
}

GetCover returns a Stream. I'm using this configuration:

<basicHttpBinding>
    <binding name="StreamedBindingConfiguration" messageEncoding="Mtom" maxBufferSize="65536"
                 transferMode="Streamed">
    </binding>
</basicHttpBinding>

The Client code is:

 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();
        }
    }

I need to know when a client download is successful without calling the service again.


You can't know when the download is successful. You can only know when the service has sent all of the data.

The only way to know if the client has received all of the data is for the client to tell the service that it has received all of the data.


How are they downloading the files? Using your WCF service? If so, you must be streaming the contents to them so just determine wehn the stream read has ended then do whatever you need to do.

0

精彩评论

暂无评论...
验证码 换一张
取 消