У меня есть метод веб-службы, который я вызываю, который является сторонним и вне моего домена. По какой-то причине время от времени веб-служба терпит неудачу с тайм-аутом шлюза. Его прерывистый вызов и вызов к нему сразу после неудачной попытки могут преуспеть.
Теперь я остаюсь с дилеммой кодирования, у меня есть код, который должен делать трюк, но код выглядит как любительский час, как вы увидите ниже.
Это действительно плохой код или приемлемый с учетом использования? Если это не приемлемо, как я могу его улучшить?
Постарайтесь, чтобы у вас было лицо, глядя на него.
try
{
MDO = OperationsWebService.MessageDownload(MI);
}
catch
{
try
{
MDO = OperationsWebService.MessageDownload(MI);
}
catch
{
try
{
MDO = OperationsWebService.MessageDownload(MI);
}
catch
{
try
{
MDO = OperationsWebService.MessageDownload(MI);
}
catch
{
try
{
MDO = OperationsWebService.MessageDownload(MI);
}
catch (Exception ex)
{
// 5 retries, ok now log and deal with the error.
}
}
}
}
}