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.