I'm working on a project that uses a Windows Mobile device to call a web service.
There's a requirement that states that if a service call fails then the user should be prompted to retry. Currently, there's a service agent which calls all the methods on the web service proxy, and if the call fails there's some code which prompts the user to retry, and then trys the call again. It looks something like this:
public void MyServiceCall(string stringArg, bool boolArg, int intArg)
{
try
{
MyWebService.MyServiceCall(stringArg, boolArg, intArg);
}
catch(SoapException ex)
{
bool retry = //a load of horrid code to prompt the user to retry
if (retry)
{
this.MyServiceCall(stringArg, boolArg, intArg);
}
}
}
The stuff in the catch looks a lot messier on the system than in that snippet, and the CTRL-C CTRL-V pattern has been used to replicate it in every service call. I'd like to refactor this duplicated code into a method but I'm unsure of the best way to retry the method call. I was thinking of having a delegate as an argument to my new method, but since I won't know the signature I'm unsure of how to do this in a generic way. Can anyone help? Thanks.