Introduction
This blog gives a simple method to check if a web service is up and connections can be made to it.
Overview
The below method will check if we are able to connect to a web service with the URL "url".
You can pass the web service url to the TestConnections method and the method will return success or failure.
The method uses simple HttpWebRequest and HttpWebResponse to check if the url is up.
The below method will check if we are able to connect to a web service with the URL "url".
You can pass the web service url to the TestConnections method and the method will return success or failure.
The method uses simple HttpWebRequest and HttpWebResponse to check if the url is up.
- /// <summary>
- /// Checks the connection to service
- /// </summary>
- /// <param name="url"></param>
- /// <returns></returns>
- public string TestConnection(string url)
- {
- try
- {
- // try accessing the web service directly via it's URL
- HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
- request.Timeout = 30000;
- using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
- {
- if (response.StatusCode != HttpStatusCode.OK)
- {
- Logger.Log(LogCategory.Business, LogLevel.Warning, Constants.ConnectionFailure);
- return Constants.ConnectionFailure;
- }
- else
- {
- return Constants.ConnectionSuccess;
- }
- }
- catch (WebException ex)
- {
- Logger.Log(LogCategory.App, LogLevel.Warning, string.Format(CultureInfo.InvariantCulture, "Error
ing connection to web service at \"{0}\":\r\n{1}", url, ex)); - throw;
- }
- catch (Exception ex)
- {
- Logger.Log(LogCategory.App, LogLevel.Warning, string.Format(CultureInfo.InvariantCulture, "Error test
- ing connection to web service at \"{0}\":\r\n{1}", url, ex));
- throw;
- }
- }
Gowtham RajamanickamPosted Apr 25, 2015, 6:30 AM
good
Gowtham RajamanickamPosted Apr 25, 2015, 6:30 AM
good
Deepti VelagaPosted Sep 29, 2014, 7:28 AM
The first thing is we can log the error in a log file and also send a notification to the user that the service is down.This is a simple method to check for availabilty.We can further enhance to send a email about the webservice status to the relevant groups to work on it....
Saravanakumar SekaranPosted Sep 27, 2014, 10:46 PM
Nice
Santhosh SubramaniamPosted Sep 25, 2014, 12:58 AM
usefull
Mahesh ChandPosted Sep 24, 2014, 10:20 PM
This is great Deepti. Question? So once you know the service is down, what you're doing next? How are you notifying the support?