Skip to content

Instantly share code, notes, and snippets.

@yemrekeskin
Created June 15, 2013 09:35
Show Gist options
  • Save yemrekeskin/5787539 to your computer and use it in GitHub Desktop.
Save yemrekeskin/5787539 to your computer and use it in GitHub Desktop.
Checking WebServices running status
public static class WebServiceExtention
{
public static bool isWebServiceRunning(this string url)
{
if (String.IsNullOrEmpty(url))
throw new ArgumentNullException();
try
{
var request = (HttpWebRequest)WebRequest.Create(url);
var response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
// to add tracelistener (txt file logs)
Trace.Write(string.Format("{0} Available", url));
return true;
}
else
{
Trace.Write(string.Format("{0} Returned, but with status: {1}", url, response.StatusDescription));
return false;
}
}
catch (Exception ex)
{
// not available at all, for some reason
Trace.Write(string.Format("{0} Unavailable: {1}", url, ex.Message));
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment