One method that I've used is to create a webservice with a boolean method that always returns "true". Call it from your app, and if you get any exceptions, or "false", you're not connected.
[WebMethod]
public bool IsAvailable()
{
return true;
}
and call it:
private bool IsOnline()
{
Cursor = Cursors.WaitCursor;
var proxy = new WS();
bool IsOnline = false;
try
{
IsOnline = proxy.IsAvailable();
}
catch (System.Net.WebException WebEx)
{
NameValueCollection nvc = new NameValueCollection();
nvc.Add("WebException Status", WebEx.Status.ToString());
if (WebEx.Status == System.Net.WebExceptionStatus.ProtocolError)
{
nvc.Add("Status Code", ((System.Net.HttpWebResponse)WebEx.Response).StatusCode.ToString());
nvc.Add("Status Description", ((System.Net.HttpWebResponse)WebEx.Response).StatusDescription);
}
ExceptionManager.Publish(WebEx, nvc);
}
catch (Exception)
{
IsOnline = false;
}
Cursor = Cursors.Default;
return IsOnline;
}