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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gregoryyoungCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.