How to detect client timeout exception on server side?

I use the synchronous WCF service, which works well in 99% of cases, but in some very rare cases, the client stops until the server has finished processing. Is there a way to detect client timeout on the SERVER side? I could use an async operation, but in this case, detecting a server timeout would save me a lot of work. I use net.tcp binding if that matters.

+6
source share
1 answer

For net.tcp, http, etc. absolutely not. (see comments above for some ideas, and may also be different for other protocols / bindings / etc.)

The reason is that server-side WCF infrastructure code will not use the channel until it completes the implementation of the service operation implementation code and sorts the response. Only then he will try to send a response and at that moment he will understand that the connection has already been interrupted by the client.

When the server receives this error, the user code (your implementation of the service operation) is already executed and therefore you can no longer respond to this. Perhaps this is possible from the dispatcher or another distribution point, but I personally have not tried it. However, this also will not save your server from unnecessary work, because, as said, disconnecting a client will still be recognized only when the server is really trying to send a response.

One โ€œsimpleโ€ way to alleviate such problems may be to split the work performed into several service operations / calls (if at all possible, and not accidentally enter the server-side state in the process). Or, as others have said, ask the client to implement the โ€œPingโ€ interface, which the server can use to check if the client remains โ€œaliveโ€ and an answer is still needed.

+1
source

Source: https://habr.com/ru/post/988913/


All Articles