check webservice is up or not?

smriti

Regular
Joined
Jan 7, 2005
Messages
54
Hi,

I need to write a program to check whether a webservice is up or not?
The program should take the service as input and determine whether the webservice is up or not?
Can you suggest me some ideas.

Thanks,
smriti
 
I'm not sure what you mean.

Why not write a web service that returns a value and call this in your windows service periodically.
 
Create a windows service, that calls a web method every few minutes using the http request and http response methods. I had to do this before to keep an eye on another web service and database. If I didn't get a reply, I waited for 1 minute and retried to call the web service and incremented my failed response counter from 0 to 1. If still no reply, I waited for 1 more minute and retried. If on the third attempt I got no reply, I auto-generated a SMS message and sent it to a number of support personnel. If however, I got a valid reply I used to reset my failed response counter to 0.

I used to call the web service 3 times just to cover my self, the first time it failed may be down to a delay in replying/slow connection etc. and I didn't want to be sending out SMS messages and annoying people.

I'll try and dig out some code for you if I get a chance.

Mike55.
 
Untested, but something like this should work.

C#:
            System.Net.HttpWebRequest client = 
                (HttpWebRequest)System.Net.WebRequest.Create("http://www.yoursite.com/service.asmx/");

            client.Timeout = 60000;

            System.IO.Stream strm = client.GetResponse();
            System.IO.StreamReader sr = new System.IO.StreamReader(strm);
            string line;
            do
            {
                line = sr.ReadLine();
                listbox1.Items.Add(line);
            }
            while (line != null);
            strm.Close();
 
Back
Top