我正在编写一个程序,我在那里使用webservice客户端。 24-7-365。 使用默认频率,程序在服务器上运行。
我的问题是,当webservice(由我们的某个商业供应商提供的webservice)关闭且我的对象创建失败时,我该如何处理?
摘要:
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;
}
}
// 使用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;
}
}
}
正确的方法 我觉得我的做法是错的,但我该怎么办呢? 提前谢谢。
答案 0 :(得分:1)
就像我说的那样,你在SLA上意识到你想要允许或交付。 致力于标记此类主题的人经常会参考本书来解释一些与技术无关的概念。
https://pragprog.com/book/mnee/release-it
" n发布它!,Michael T. Nygard向您展示如何设计和构建您的应用程序以应对它将面临的严酷现实。您将学习如何设计应用程序以获得最大的正常运行时间,性能和投资回报...... "
这还取决于您选择的部署以及您选择的客户。微服务社区有很多有趣的概念。像一次性服务等 因此失败是可以的,但是失败并且预计会有另一个实例接管工作负载。谷歌从netflix technoligy团队出来的 Chaos Monkey 。 因此,请花点时间......研究......考虑您的风险和预算......并做出技术选择。有关该主题的大量信息。 HTH