Can anyone advise what the best way to check (using .NET 3.5) if a remote server is available?
I was thinking of using the following code but would like to know if
If you be using a previous version of .NET Framework, like me, the version 2, you'll have no Ping and no System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable(). Then, you can use HttpWebRequest to check a host disponibility:
public static bool AccessToWebService()
{
string host = "http://192.168.99.41";
try
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(host);
request.Method = "HEAD";
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
return response.StatusCode == HttpStatusCode.OK;
}
catch (Exception)
{
return false;
}
}