eMi
eMi

Reputation: 5628

Set Timeout Async Webservice Call?

My Webservice is inheriting from System.Web.Services.Protocols.SoapHttpClientProtocol.

I tried to set the Timeout:

service.Timeout = 5000; // 5 secs

but nothing happens - neither a TimeoutException nor anything else. Once I tried it without any declarations and it took 190 Secs for a "Connection Timed Out". 190 is strange as I thought, that the Default is 100 Secs.

Anyway, the Timeout Property seems to work on "only" synchronous calls, so in my case I'm not wondering why its not working.

I'm calling the methods asynchronous like that:

service.GetInfoCompleted += service_GetInfoCompleted;
service.GetInfoAsync();

How could I solve my Problem?

Any Help appreciated!

Upvotes: 2

Views: 3305

Answers (2)

eMi
eMi

Reputation: 5628

As there is no "native" way of doing so - I had to implement an own Timer.

After the Elapsed time b.e 10 Secs I can call Abort() of the async method call

Upvotes: 1

alex
alex

Reputation: 12654

Your service.GetInfoAsync() should return IAsyncResult . You can wait for 5 seconds for operation to complete, and if it does not, handle the timeout:

var result = service.GetInfoAsync();

if(!result.AsyncWaitHandle.WaitOne(5000)){
     // handle timeout
}

Upvotes: 0

Related Questions