I was looking for ways to check and report the status of a webservice, and came across both these classes. Is there any benefit in using one of these over the other?
-
3Why do you believe that Ping and WebClient are the same? Sorry to say that but you could also have asked whats the difference between boolean and int, sure both are primitive types but they have so less in comon that asking what the difference is, kind of seems strange. – Rand Random Jun 07 '17 at 13:39
-
@RandRandom making this question into "far too broad to be answered on StackOverflow". – MakePeaceGreatAgain Jun 07 '17 at 13:42
2 Answers
Ping tells you whether a machine is accessible.
WebClient allows you to make HTTP (web) requests.
You almost certainly want the latter. Or consider HttpClient - https://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.118).aspx .
You may find https://stackoverflow.com/a/7523808/34092 useful as well.

- 23,389
- 6
- 40
- 63
Ping sends ICMP echo requests to the target machine. Many machines will not respond to these requests because firewalls. So this is an unreliable means of checking if a machine is running, let alone running the service you're interested in connecting to.
The best way to check if a service is running is to try and use it (without any kind of pre-check) in the way that the service provider intends you to use it. If it doesn't work, then you can safely say that the service is down.

- 117,338
- 33
- 229
- 351