views:

38

answers:

0

I usually try to encapsulate my web service calls in my client side apps.

Rather than doing this:

public Guid FindUserIDSelected(string userName)
{
    MyWebServiceReference service = new MyWebServiceReference(GetEndpointBasedOnEnv(Env));
    return service.GetUserIDFromName(userName);
}

I have a static class that encapsulates the communication with the web services. It handles the endpoint resolution via determining the environment (and other such things).

So the above code changes to look like this:

public Guid FindUserIDSelected(string userName)
{
    return Communication.GetUserIDFromName(userName);
}

But now I am having an issue. Silverlight only supports Asynchronous calls (at least as far as I am seeing). So calling a web service and then returning the value in an encapsulated call does not work.

The best I can come up with is passing in a delegate that is used in the Communication class for the completed event:

private Guid foundUserID;

public void FindUserIDSelected(string userName)
{
    Communication.GetUserIDFromName(userName, GetUserIDCompleted);
}

private void QuestionRecieved(object sender, GetUserIDFromNameCompletedEventArgs e)
{
    foundUserID= e.Result();
}

This has several problems (in my opinion).

  1. I now have elements of the web services that have broken encapsulation (the completed call is really the web service return. I don't want the rest of my classes to have to care about the services).
  2. I have had to expose my result (foundUserID) at the class level.

Am I being too rigid? Is that good enough? Is there a better way?

Am I the only one who has this issue?