When writing a Silverlight app hooked up to a WCF Web Service, the only option we are presented with in using the Web Service is to make asynchronous calls to the WS interface.
i.e.
WebService client = new WebService();
client.ServiceMethodCompleted += new EventHandler<Args>(client_Handler);
client.ServiceMethodAsync();
client.close()
...followed by
void client_Handler(object sender, Args e)
{
//Next step, possibly another method?
}
While I understand the reason for asynchronous calls when writing webapps (safety net), what type of design pattern would one use if a method was written where each step was dependent on the result of the Web Service call?
For instance, if there was a method in the Web Service that checked the user credentials of the visitor, and depending on the group of that user, would perform some action.
public MyPage() //Constructor
{
CheckCredentialsAsync();
if(result.IsUserTypeA)
{
//something complex
}
else if(result.IsUserTypeB)
{
//something else complex
}
...etc
}
Is there a way to accomplish this without using a 'domino' design of methods triggered by the previous asynchronous calls completed event? It seems as though it can get messy if there is a lot of client/service interaction.
Thanks!