Abort WCF server task if client is disconnected

996 views Asked by At

We have a WCF service hosted under Windows service. The client of this service has set up closeTimeout, receiveTimeout, openTimeout, sentTimeout set to 5 minutes. Service also has the same. In certain circumstances, WCF service may take more than 5 minutes to process a task. In this case, client aborts the call, but service process keeps on running until it finishes its job.

Now, the question is... is there any configuration/technique available which would detect that client has disconnected or timedout (or something else?) so that WCF service can just abort its tasks?

1

There are 1 answers

0
CodeCaster On

It's not easy, if not impossible (so this is pretty much a duplicate question).

Do you really want the operation to be cancelled when the client disconnects? Otherwise you could implement some state-like mechanism, using some sort of work queue.

A clients then calls QueueQuery(query), which does nothing more than that and returns an identifier to the just queued query. After that, the client can keep polling QueryStatus(id) to retreive the status (e.g. "Queued", "Running", "Finished"), and when a query has finished, it can call QueryResults(id).

Meanwhile another service (i.e. a Windows service, not a WCF service) keeps executing all queued queries.