I’m trying to figure out if there is an easy way implementing a retry to the service when it sends a fault. lets say for eg:
Private Function SaveEmployee(emp as Empoyee)
Try
...
returnval = service.SaveEmployee(emp)
Catch ex as exception
'if exception requires retry eg:end point not found or database is not responding then
'call retry func/class
RetryOperation(...)
End Try
End Function
in the above sample how can I make a generic RetryOperation class which can take any function and call it 3 or 4 times with an interval before informing the user that the operation cannot be completed.
I’m hoping it’s possible to make a generic method rather than have duplicate code in all the service call functions
any samples in C# or vb.net will be really appreciated.
Thanks
If it is a call that you might want repeated if it fails why not use the Repeat functionality at once, if the service call is successful it will just be called once, if the service call fails it will retry x number of times, if it fails on the x:th time it will throw an exception
How about something like this, please note this is greatly simplified, you will need to add error handling and such:
Create your repeat method like this:
Use it like this
Same thing in VB.NET
Use it: