how to get the status of a remote server?

akohan
akohan used Ask the Experts™
on

hello group,

In part of my website I'm using a third part service when user can click on a link and login to it. Sometimes the service goes down and I need to show a notification showing the status of a the service.
either it is down or up and running.

Thinking to write a script using C# or VB.NET for this matter. can somebody give me some hints on this ?

Regards,
ak


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
The easiest way I can think of is just to try to use one of the methods of the web service and catch an exception or query its result.  Pick a non-destructive method to call and wrap it in a try/catch block.

If its a regularly-called service, you may want to cache the result for a few mins between calls...
try
{
    MyWebService mws = new MyWebService();
    mws.SafeMethod();
}
catch
{
    statusLabel.Text = "The web service is unavailable";
}

Open in new window

Author

Commented:


Thanks for your response. I'm a little confused here. What is MyWebService in your code? would you please give me some insight into this?

Regards.

Author

Commented:

One thing I had to explain that currently I'm not using any C# or VB.NET code. the website is just a few pages made of html/css.

There is a link in one of the pages that people can click and get to a service. I need to check their domain periodically and return a status.

Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Sorry, I was assuming an ASP.NET site consuming a third-party WSDL web service.  Maybe you need to explain a little clearer:

  -  do you have an ASP.NET website in place?
  -  what is the web service that you are trying to consume?

>> There is a link in one of the pages that people can click and get to a service
A link to what?  Another web site?

J.

Author

Commented:



>>  do you have an ASP.NET website in place?
>>  what is the web service that you are trying to consume?

OK, consider having a regular website only made of HTML, CSS and ... but runs in IIS. It has a link to a third party online site as Blackboard.

I can use ASP.NET on my server and the web application I'm using is Blackboard.

Regards.


If you're not using ASP.NET currently, you'll need to do this in client script.  You m,ay want to ask the guys in the JavaScript area to be sure, but you may be able to do this by embedding a hidden image or iframe on your page and binding a JS function to its onerror event property:
<html>
  <head>
    <script type="text/javascript">
      function BlackboardDown() { 
        window.alert('Blackboard is down'); return false; 
      }
    </script>
  </head>
  <body>
    <img style="display:none" src="http://www.blackboard.com/includes/images/master/logo.gif" onerror="javascript:return BlackboardDown();" />
  </body>
</html>

Open in new window

Author

Commented:

Thank you, it. Would you please tell me how I can do it using ASP.NET?

regards.
Most Valuable Expert 2012
Top Expert 2014
Commented:
Hi,
You can use a HTTPRequest to request a page from the website. If the page is retrieved successfully then the site is up otherwise its not accessible.

http://www.codeproject.com/KB/cs/Browsing_the_WEB_with_C_.aspx
Assuming a familiarity with ASP.NET, you'll have a Page, with a Page_Load method.  

You use the HttpWebRequest and HttpWebResponse objects to try to connect to a known page in the site.  If the HttpWebResponse's Status is not 200, or a WebException is thrown, the site is down.
protected void Page_Load(object sender, EventArgs e)
{
    const string UP = "The Blackboard website is available",
                 DOWN = "The Blackboard website is down";
    try
    {
        const string URL = "http://www.blackboard.com/";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);
        HttpWebResponse resp = (HttpWebResponse).GetResponse();
 
        statusLabel.Text = (resp.StatusCode == HttpStatusCode.OK) ? UP : DOWN;
    }
    catch (WebException)
    {
        statusLabel.Text = DOWN;
    }
}

Open in new window

Author

Commented:

Can't I choose a 2 answers?! I see only one link as "accept"

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial