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,

  1. Is it expected feature or my bug that if no response from server after call AsyncXXX method, complete event handler will not be called?

  2. 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.

    <httpRuntime executionTimeout="120" />

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.

Need Your Help

Use audio files or text to speech for iOS application

ios audio text-to-speech voice

I am creating an iOS game in which I have to inform user about events in the game with voice, that you have moved one piece, 2 pieces or well done you have performed well.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.