String Writer

my tech stuffs…

Validate Web service in C#

leave a comment »

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;
  }
}

Written by visvabalaji

September 16, 2011 at 12:23 pm

Posted in C#, SourceCode

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.