473,789 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 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
Dec 20 '05 #1
3 2562
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 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();
break;
}
}

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

"Imaginatio n is more important than knowledge." - Einstein

"Gravitatio n 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 SleepForInterva l method on the web service takes an int and sleeps
the thread by the int interval (in millisecods). */
ar = WS.BeginSleepFo rInterval(10000 ), null, null);
DateTime start = DateTime.Now;
while (IsCompleted == false)
{
DateTime elapsed = DateTime.Now;
TimeSpan ts = elapsed - start;
if (ts.TotalSecond s > Timeout )
{
WS.Abort();
break;
}
}

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

"Imaginatio n is more important than knowledge." - Einstein

"Gravitatio n 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
2521
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 onTimer event wouldn't be raised again after few hours. I checked the msdn and Microsoft claims that it is a bug in their .net framework as follows: http://support.microsoft.com/default.aspx?scid=kb;en-us;842793
5
1640
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)? Can't service generate events into monitor application? Where can I retrieve examples about monitoring windows services? Thank in advance and... sorry for my english, but I'm Italian! :-)
5
5036
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 come in, so I think I need a service vs using task scheduler. Am I correct? If yes, can someone help with how to do this? So far
0
1668
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 question - but noone seems to answer. Do i need to do anything specific to write to a text file from a windows service, much appreciated.
3
2449
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
2494
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 webservice is coming from a database. My initial idea is to run a windows service getting the schedule(s) from a db but how do I keep track of possible multiple timer events on a daily basis from within the windows service. Should I be using MSMQ or...
7
1224
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 label in a GUI, some data may come from a database. The application will be able to connect to any standard database in time, but for the time being it's access. I will need to 'bolt' this application into many other applications as time
0
1123
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 call to my COM object, which is compiled in VB.NET and it just does not work. I found out it fails at the CreateObject, and I just can't find why. If I call a COM object I had made in VB6 it works fine. If I call my COM in VB.NET from an ASP...
1
1353
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 doesn't seem to loop at all, ie, I only get the 1 round of warning messages (it also sends me a net message, but that will be removed eventually). My code for the whole service is below: Imports System Imports System.IO Imports System.Net...
0
1401
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
10408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6768
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.