Validate Web service in C#
I’ve got many web services to read IMDB content. Some of them are failed to access while testing. So I needed to check whether they are really active before accessing them.
Here’s the code snippet to check any website/web services are active.
public bool IsWebServiceActive(string webServicePath)
{
try
{
WebRequest request = WebRequest.Create(webServicePath);
return ((HttpWebResponse)request.GetResponse()).StatusCode == HttpStatusCode.OK;;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
