开发者

Cancel async web service calls

开发者 https://www.devze.com 2023-04-11 05:54 出处:网络
I need to be able to cancel async calls made to my webservice. One solution I have is to use manage my own threads, and use synchronous methods from the SOAP client. This works fine and it needs some

I need to be able to cancel async calls made to my webservice. One solution I have is to use manage my own threads, and use synchronous methods from the SOAP client. This works fine and it needs some more fine grained thread management.

If I used any of these two patterns provided from adding a web service reference, say:

var Client = new ASL_WS.SvcSoapClient()
IAsyncResult result = Client.BeginAuthenticateUser(Email, Password, new AsyncCallback(AuthCompleted));

or

var Client = new ASL_WS.SvcSoapClient()
Client.AuthenticateUserCompleted += AuthCompleted;
Client.AuthenticateUserAsync(Email, Passsword);

do any of these two patterns give me a way of cancelling the request? One use case could be: a user logs in, but wants to cancel before the authenticate call completes.

Of course, I could implement this differently by modifying the asyncState passed to these calls, and setting it to disable UI update, but it's not what I'm looking for.

Could I just just cancel all outstanding operations. Does Client.Abort() cancel such operations. What if there are many async requests, are all cancel开发者_开发百科led? Are there any other API methods that can do this?


Yes, you can use Abort method but keep below notes in mind. You can also use CancelAsync.

Abort notes: http://msdn.microsoft.com/en-us/library/aa480512.aspx

When you call the Abort method, any outstanding requests will still complete, but they will complete with a fault. This means that if you are using callbacks, your callback function will still be called for each outstanding request . When the EndInvoke method is called, or in our case, the wrapper function EndDelayedResponse, then a fault will be generated indicating that the underlying connection has been closed.

CancelAsync example: http://www.codeproject.com/KB/cpp/wsasync.aspx

0

精彩评论

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

关注公众号