Specifying Timeout for remoting calls
This week while working on a case, I discovered how to set timeout values for Remoting calls which I though is pretty cool. We have missed this attribute a lot in DCOM.
We can specify the timeout attribute on the HttpChannel and that sets the time an Http request will wait in GetResponse() method of HttpWebRequest, before it throws an exception. That in remoting translates to when you make a remoting call(sync or async) the underlying channel will wait in GetResponse() for the remote method to return data for that time, if it does not return any response within the 'timeout' period, it would timeout and throw an exception in your remoting call. Cool isn't it.
This value is set to -1 or infinite lifetime by default, that basically means that remoting calls will block forever(yuckkk.) hence leading to client hanging if the server fails to respond. Now when we talk about async calls, then as soon as you shoot an async request it(underlying remoting) starts a HttpWebRequest and waits in GetResponse() for the async method to complete. Even though your class is not waiting on async call to finish and might be doing some other work in the meanwhile. But when your object tries to see if the async method actually returned an result or not at that point of time it would let you know whether the async method returned within the specified 'timeout' from the time you send the original async request if not then it will throw an exception.
How to set:
Unfortunately I found some bugs related to this property having problem being read from config file. But it works great if you specify it programmatically:
IDictionary props= new Hashtable();
props[”timeout”] = 10000 ;//Wait for 10s in remote call.
//other properties like port etc.
HttpChannel chnl = new HttpChannel(props, .... ,....);