1

I am dealing with a web-service call that may take anywhere from a few seconds to several minutes to complete. It constructs the requested data and returns it. Right now for a long-running call into the WS the user interface (WinForms) becomes unresponsive; the user has no way to cancel the operation.

The ideal approach to solving this (I think) would be to break the operation into two web-service calls: first a request, second to get the status or available data.

But if the web-service structure cannot be changed, what is the best way to interrupt the web-service call?

UPDATE:

The WS call could be made asynchronously. If the user wants to cancel the operation, then I'd like to relieve the server of unfinished work (rather than letting the thread complete normally and throw away the response). Thread.Abort() is a possibility but I want to know if there is a better way.

The web services I am working with are WCF based. The operations are read-only, so there is nothing to undo if interrupted.

jltrem
  • 12,124
  • 4
  • 40
  • 50
  • 3
    Why not just do the web service call asynchronously? – EkoostikMartin Sep 25 '13 at 14:31
  • If you've added reference to WS as `Add ServiceReference` `WsClient` your client will have a `xxxAsync` method which returns task. you can `await` on it easily – Sriram Sakthivel Sep 25 '13 at 14:34
  • so if I run the WS call asynchronously is my only option to interrupt it [Thread.Abort](http://stackoverflow.com/questions/2251964/c-sharp-thread-termination-and-thread-abort)? – jltrem Sep 25 '13 at 16:25
  • Why do you need to interrupt it? Just set an execution timeout. – EkoostikMartin Sep 25 '13 at 17:00
  • @EkoostikMartin I updated the question with 'why'. Since the interruption is user-invoked I don't think an execution timeout is possible. – jltrem Sep 25 '13 at 17:15
  • @jltrem - okay, what you are asking for is more complicated. We need to know what type of web services you are interacting with (WCF or classic ASP.Net web services, and what version of .Net are the services coded in). Also, if you interrupt the web services, do you want it to rollback? This all gets very complex. – EkoostikMartin Sep 25 '13 at 17:19
  • The web services I am working with are WCF based. The operations are read-only, so there is nothing to undo if interrupted. – jltrem Sep 25 '13 at 17:28

1 Answers1

0

You can generate Asynchronous proxy class to implement this feature.

Please look at the following link for sample,

http://msdn.microsoft.com/en-us/library/wyd0d1e5(v=vs.100).aspx

Rajesh Subramanian
  • 6,400
  • 5
  • 29
  • 42