Created
June 15, 2013 09:35
-
-
Save yemrekeskin/5787539 to your computer and use it in GitHub Desktop.
Checking WebServices running status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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