Im writing a program, where I use a webservice client. 24-7-365. With a default frequency the program runs on a server.
My problem is how do I handle when the webservice (webservice delivered by one of our business suppliers) is down and my object fails in being created?
Abstract:
static void Main()
{
// This object is based on a webservice supplied to us by
// a business supplier.
var Plants = new foreignSupl.ExtWebServiceClient().GetPlants();
// My problems is that - when the business suppliers system is down.
// Then my program dumps.
// Code in program that depends on: Plants.
if (insertPlants(Plant, out Plants) == true)
{
insert = true;
}
}
// Approach with try catch:
// I have tried to use try catch but then I get another problem.
//
// Visual studio says:
// "The name 'Plant' does not exist in the current context.
//
static void Main()
{
try
{
var Plant= new foreignSupl.ExtWebServiceClient().GetPlants();
}
catch
{
//handling the exception.
}
// Code in program that depends on: Plants.
// Visual studio says:
// "The name 'Plant' does not exist in the current context.
// Therefore I can't compile...
if(Plants != null)
{
if (insertPlants(Plant, out Plants) == true)
{
insert = true;
}
}
}
Correct approach I sense that my approach is wrong, but how am I supposed to do this? Thanks in advance.
Like I said this heavily realize on your SLA's that you want to allow or deliver. People who work on tagling such topic often refer to this book that explain some concepts technology agnostic.
https://pragprog.com/book/mnee/release-it
"n Release It!, Michael T. Nygard shows you how to design and architect your application for the harsh realities it will face. You’ll learn how to design your application for maximum uptime, performance, and return on investment..."
It also depends on your choice of deployment as well as of your choice of clients. The Microservice community has a lot of interesting concepts. Like disposable service, etc. So failing is ok, but fail and expected to have another instance taking over the work load. Google for Chaos Monkey which came out of netflix technoligy team. So take your time... and research... take your risk and budget in account ... and make a technology choice. There is plenty of information on that topic out there. HTH