Featured post
c# - Retry a service call ONLY ONCE in the event service fails logic help -
so have function calls web service return int indicitating success or various types of failures may have occurred. after recieve result service, run through switch statement , procceed accordingly based on encountered during service execution.
private void example() { int result = executewebservice(); switch(result) { case 0: //no errors noerrorslogic(); break; case 1: // manual retry manualretrylogic(); break; case 2: // validation error validationerrorlogic(); break; default: // run time error occurred logicoptiond(); // @ point want to call service again once see if succeed break; } }
generally, i'd add call function calls sevice , runs through results on again, don't want continuously run until service succeeds. in default option want force 'retry' calling service once - , process results accordingly.
any ideas?
you can alwaus do:
private void example(bool retry = true) { .... default: if(retry) { example(false); } break; }
just add parameter , have function call if fails. pass in false value parameter tells function if fails again, don't anything.
in c# 4.0 example(bool retry = true)
can set default value, don't have worry existing code not having true value set. in 3.5 or below create overloaded method on parameter , 1 without. 1 without calls 1 so:
example() { example(true); }
- Get link
- X
- Other Apps
Comments
Post a Comment