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
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:
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.