I am using synchronous WCF service which works well 99% of the time, but on some very rare occasions client times out before the server finishes processing. Is there a way to detect, on the SERVER side, that the client has timed out? I could use async operation, but in this case server-side timeout detection would save me quite a lot of work. I'm using net.tcp binding, if this matters.
Before using the response from the request, you can check for a timeout error using the os. IsTimeout() method. It returns a boolean indicating whether the error is known to report a timeout that occurred.
You can control the connection and socket timeout of the loading of the WSDL definition by setting enable-wsdl-discovery-timeouts . Use the value -1 to use the default of the underlying infrastructure. Use the value 0 to disable the timeouts. Use a positive integer to specify a timeout in milliseconds.
Client timeouts set a limit on how long they are willing to wait for a response to come back—and in some cases be completed. Server timeouts set a limit on how long the connection should remain open.
Start Learning. In Selenium, TimeOut exception occurs when a command takes longer than the wait time to avoid the ElementNotVisible Exception. If the commands do not complete even after the wait time is over, a TimeOut Exception is thrown.
For net.tcp, http, etc. in general no. (see comments above for some ideas; also it might be different for other protocols/bindings/etc.)
The reason is, that the WCF infrastructure code on the server side will not use the channel before it has finished executing the service operation's implementation code and marshalling the response. Only then it will attempt to send the response and at this point recognize that the connection has already been aborted by the client.
When the server gets that error the user code (your service operation implementation) is already done and thus you cannot react to that from there anymore. It might be possible from within a dispatcher, or other extension point, but personally I have not tried. However, that also would not save your server from unnecessary work, because as said, the client disconnect will still only be recognized when the server actually attempts to send the answer.
One "simple" way to mitigate such issues might be to split the work being done into several service operations/calls (if at all possible; and not accidentally introducing server-side state in the process). Or as others have said, have the client implement a "Ping" interface that the server can use to check if the client is still "alive" and the response is still needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With