timeout for asynchronous web service call in C#
I am using C# and created a proxy from a ASP.Net asmx Web Service at client side, by using Add Web Reference... feature of VSTS 2008.
And I am using the asynchronous method call model (i.e. call the AsyncXXX method, which will return immediately) and handles the complete event (I add event handler to handle the complete even when the reponse is received from server side).
I find if there is no response from server for a long time, the complete event will not be fired.
My questions are,
Is it expected feature or my bug that if no response from server after call AsyncXXX method, complete event handler will not be called?
Are there any way to assign timeout value -- so that I do not wait on the complete event handler infinitely?
thanks in advance, George
In the web.config for your webservice you can set a timeout (You will also need to change to not be in debug mode if it is). This should then cause it to throw an exception that will raise your completed event. You will then need to inspect for an exception to see if it passed or failed.
<system.web> <httpRuntime executionTimeout="120" /> </system.web>
If you want your web service to never timeout you can put this line in the web services class:
this.Timeout = System.Threading.Timeout.Infinite;
SoapHttpClientProtocol which your proxy should inherit from has a Timeout property inherited from its ancestor WebClientProtocol. It could answer your second question.