I have a particular requirement when I call a web service; I have to call the
web service, wait until the web service returns or my timeout expires
(whichever is sooner) and exit.
I tried to use the MSDN example to poll a web service and abort it after a
specified timeout.
Have a look at the code below:
/* Set the timeout in seconds*/
int Timeout = 20;
/* create an instance of the web service proxy*/
POLL.Service1 WS = new POLL.Service1;
/* The SleepForInterva l method on the web service takes an int and sleeps
the thread by the int interval (in millisecods). */
IAsyncResult ar = WS.BeginSleepFo rInterval(10000 ), null, null);
DateTime start = DateTime.Now;
while (ar.IsCompleted == false)
{
DateTime elapsed = DateTime.Now;
TimeSpan ts = elapsed - start;
if (ts.TotalSecond s > Timeout )
{
WS.Abort();
}
}
---
What I have found is that the code snippet does not behave as expected, ie
the IsCompleted flag NEVER gets set to true, even though I know that the web
service call has completed. It just loops for ever in the while loop until
the the abort statement gets called.
Any help would be appreciated.
--
Regards
----------------
Shailen Sukul
MCSD MCAD
"Imaginatio n is more important than knowledge." - Einstein
"Gravitatio n is not responsible for people falling in love." - Eistein