473,385 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Web Service Polling

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 SleepForInterval method on the web service takes an int and sleeps
the thread by the int interval (in millisecods). */
IAsyncResult ar = WS.BeginSleepForInterval(10000), null, null);
DateTime start = DateTime.Now;
while (ar.IsCompleted == false)
{
DateTime elapsed = DateTime.Now;
TimeSpan ts = elapsed - start;
if (ts.TotalSeconds > 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

"Imagination is more important than knowledge." - Einstein

"Gravitation is not responsible for people falling in love." - Eistein
Dec 20 '05 #1
3 2535
sorry need to ensure that break was called after abort.

/* Set the timeout in seconds*/
int Timeout = 20;

/* create an instance of the web service proxy*/
POLL.Service1 WS = new POLL.Service1;

/* The SleepForInterval method on the web service takes an int and sleeps
the thread by the int interval (in millisecods). */
IAsyncResult ar = WS.BeginSleepForInterval(10000), null, null);
DateTime start = DateTime.Now;
while (ar.IsCompleted == false)
{
DateTime elapsed = DateTime.Now;
TimeSpan ts = elapsed - start;
if (ts.TotalSeconds > Timeout )
{
WS.Abort();
break;
}
}

--
Regards
----------------
Shailen Sukul
MCSD.Net MCSD MCAD

"Imagination is more important than knowledge." - Einstein

"Gravitation is not responsible for people falling in love." - Eistein
Dec 20 '05 #2
Hello Shane,

Hope this heps: http://www.yoda.arachsys.com/csharp/...latility.shtml

S> I have a particular requirement when I call a web service; I have to
S> call the web service, wait until the web service returns or my
S> timeout expires (whichever is sooner) and exit.
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Dec 20 '05 #3
I tried locking the object as follows, alas to no avail:

static IAsyncResult ar;
static readonly object stopLock = new object();

static bool IsCompleted
{
get
{
lock (stopLock)
{
return ar.IsCompleted;
}
}
}
/* Set the timeout in seconds*/
int Timeout = 20;

/* create an instance of the web service proxy*/
POLL.Service1 WS = new POLL.Service1;

/* The SleepForInterval method on the web service takes an int and sleeps
the thread by the int interval (in millisecods). */
ar = WS.BeginSleepForInterval(10000), null, null);
DateTime start = DateTime.Now;
while (IsCompleted == false)
{
DateTime elapsed = DateTime.Now;
TimeSpan ts = elapsed - start;
if (ts.TotalSeconds > Timeout )
{
WS.Abort();
break;
}
}

--
Regards
----------------
Shailen Sukul
MCSD.Net MCSD MCAD

"Imagination is more important than knowledge." - Einstein

"Gravitation is not responsible for people falling in love." - Eistein
"Michael Nemtsev" wrote:
Hello Shane,

Hope this heps: http://www.yoda.arachsys.com/csharp/...latility.shtml

S> I have a particular requirement when I call a web service; I have to
S> call the web service, wait until the web service returns or my
S> timeout expires (whichever is sooner) and exit.
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

Dec 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ray | last post by:
Hi, I just wrote a windows service application to call a function of another object periodically. I used System.Server.Timer and I found that it works fine within the first 2 hours but the...
5
by: Wally | last post by:
Hi Hi need to monitoring my windows service written in VB NET. How can my monitor application "feel" that my service has made something? Is the only way a polling (for example on a Db table)?...
5
by: Belsam | last post by:
Hi all I need to create a windows service that will wait for a file to be copied somewhere, write it to the database, and then move the file to a storage area. I don't know when the file will...
0
by: Seth | last post by:
For some reason my service works fine except that it will create the file in my c drive, but will not write to the file. Sorry if this is a duplicate post, i have found some that ask the same...
3
by: Chris | last post by:
Hi, I need to create a windows service that will poll a database every 10 sec and print processed orders to a printer. Where can I find info on this? Thanks
1
by: Alex | last post by:
Hi, Apologies if this not quite the right forum, but I am looking for ideas/method of polling a webservice with different parameter values at different times, the schedule for polling the...
7
by: TClancey | last post by:
Hi all. I hope someone can give me a few pointers on 'best practice' for an app I'm about to start. I'm writing a small and simple label design application, users will define text fields on the...
0
by: pdube | last post by:
I have been trying for a few weeks to have a service that calls a COM in .NET I made a service in .NET following simple instructions I found on the web. It worked fine. Then I needed to make a...
1
by: CraigMuckleston | last post by:
I have built a windows service that should check whether a page can be returned from a site (from various servers). If not, it logs to the Application Error log. My trouble is this. It runs once, but...
0
by: tompar | last post by:
I am new to WCF. I need to add some polling logic which is basically going to call a method every few mintues to check for new data on a share. How do I do this in a WCF service?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.