开发者

WCF file transfer with cancellation support

There are a lot of questions regarding file transfer with WCF. I've got everything working, including larges files in "chunked" mode. I have the option to cancel the file upload from the sending party (the one that starts the upload) and a callback interface to notify when the transfer is accepted, and canceled.

My problem is cancelling the the uplo开发者_JS百科ad from the receiving end. I can just force the channel to close, but i would like to notify the sending party of the cancellation. I'm not getting a solution for this. Any help?

Thanks

Update:

I already figured it out. See the comment below. The service interface looks like this:

By the way, the service interface looks like this:

[ServiceContract(SessionMode = SessionMode.Required, 
CallbackContract = typeof(IFileTransferServiceCallback))]
public interface IFileTransferService
{
        [OperationContract(IsOneWay = true)]
        void RequestSendFile(FileTransferInvitation request);

        [OperationContract(IsOneWay=true)]
        void SendData(string id, byte[] data, int length);

        [OperationContract(IsOneWay = true)]
        void SendCancel(string id); 

        [OperationContract(IsOneWay = true)]
        void SendEnd(string id);

        [OperationContract(IsOneWay = true)]
        void RequestSendCancelConfirmed(string id);
}


public interface IFileTransferServiceCallback
{
        [OperationContract(IsOneWay = true)]
        void SendStarted(FileTransferInvitation transfer);

        [OperationContract(IsOneWay = true)]
        void RequestSendCancel(string id);

        [OperationContract(IsOneWay = true)]
        void SendCompleted(string id, Exception error);
}


This was my solution that is working fine:

Added a method on the callback interface to request a cancellation form the server. On the client side i use a flag that is set to true when te cancelation request is made. Then stop sending data, confirm the cancellation to the server and close the channel (cleaning up the temp files...).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜