Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7248961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:12:56+00:00 2026-05-28T22:12:56+00:00

I am calling a web service via a httpwebrequest, and getting a response. The

  • 0

I am calling a web service via a httpwebrequest, and getting a response. The web service is meant to run 24/7.

What is the best way to structure this code, with checks that the service is “available”?

What I have:

if (NetworkIsAvailable())
{
  // Call web service
 // Handle exceptions within here.
}


else
{
 // to throw a relevant exception that there is no network
}

Is it wise to throw an exception, or just return false? The svc should never be down

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:12:57+00:00Added an answer on May 28, 2026 at 10:12 pm

    Depending on the type of data you are receiving back, the frequency of checks, etc I would use a general purpose solution that tries the connection multiple times on a failure and then categorizes “exceptions” on failure (no two exceptions are ever the same in my experience).

    For instance:

    var failCount = 0;
    var succeeded = false;
    
    while ((failCount < 3) && (!succceeded)) {
       try {
          //call service....
          succeeded = true;
       } catch(WebException wex) {
          //handle wex, for instance look for timeout and retry
       } catch(...) {
         //Handle other exceptions differently...
         LogError("BOOOM: " + excep);
         throw;
       } catch(Exception ex) {
         //handle a general exception
         failCount++;
       }
    }
    
    if (failCount >= 4) {
       //Unspecified error multiple times, react appropriately...
    }
    

    Obviously you dont want to do this multiple tries if its expensive call, here I assume its a sort of “heartbeat” check thats not too expensive. The “failCount” can be adjusted depending on how “turbulent” you expect the connection to be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this error when calling a web service method which writes to
In sharepoint my web part is calling a web service. This web service does
My superior once told me that a bad way of calling a web service
I’m calling a web service via WCF (w/ .NET 4.0) that requires basic HTTP
I am querying a sharepoint list via the web service api. Calling the service
Visual Studio makes calling a web service easy, trying to figure out what is
I'm calling a web service that returns an array of objects in JSON. I
I am calling a web service from a C# forms based app. ServReturnType obj
I'm calling a web service from a console app - all in C# on
I am calling a web service to return XML data for states/provinces of countries.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.