How do I use C#.NET to ping a web service?

I have a problem where when I call my web service from a WIndows client, it times out when the service is down.  Do I'd like to ping the service before I call it.

Does anyone know how to do that?

thanks.
newbieweb
newbiewebSr. Software EngineerAsked:
Who is Participating?
 
gregoryyoungConnect With a Mentor Commented:
to ping the machine you can use this http://msdn2.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx

but that doesn't mean that the webservice is actually up and running. To determine if it is up and running you would need to actually make a call to it.
0
 
newbiewebSr. Software EngineerAuthor Commented:
But the problem I am ghaving is that it times out when the webservice is down.  And my exception handler is of no use at that point.  And when I run from an executable, the program crashes.

Any idea how to prevent this?
0
 
gregoryyoungCommented:
why is your handler of no use? You can catch a webservice being down ....

try {
   webservice.Call();
}
catch {
    ...
}

or if you use the Begin/End pattern for async you will get an exception when you call the End method in your handler
0
 
newbiewebSr. Software EngineerAuthor Commented:
Here is the exact code which calls my web service:

Damn!  I just saw it's not in a try catch block!!!

Sory for the hassle!

newbieweb

        public void GetGps()
        {
            if (gpsGetter != null)
            {
                string[] gpsEventList = null;
                if (lastGpsTime == null)
                {
                    lastGpsTime = new TLDateTime();
                    lastGpsTime.SubtractMinutesSeconds(30, 0);
                    gpsEventList = (string[])gpsGetter.GetGpsEvents(lastGpsTime.TheTime, "PizzaHut001", loopCount >= 8); //"PizzaHut001");
                }
                else
                {
                    gpsEventList = (string[])gpsGetter.GetGpsEvents(lastGpsTime.TheTime, "PizzaHut001", loopCount >= 8); //"PizzaHut001");
                }
                loopCount++;
                if (loopCount > 8)
                {
                    loopCount = 0;
                }
                WriteGpsRecords(gpsEventList);
            }
        }
0
All Courses

From novice to tech pro — start learning today.