Consuming WCF services in Silverlight using Async CTP

Here is a small sample of how you can consume WCF services using the new Async CTP features.

Example, filling a listbox with categories of some sort.

private async void FillCategories()
    var client = new MyServiceReference.MyServiceClient();
    //yield untill all categories have been fetched.
    var categories = await client.GetCategoriesTaskAsync();
    categoriesListBox.DataContext = categories;


//this extension makes it possible to get a Task of T back from our service client
public static class MyServiceClientExtensions
    public static Task<IList<Category>> 
                GetCategoriesTaskAsync(this MyServiceClient client)
        var taskCompletion = new TaskCompletionSource<IList<Category>>();
        client.GetCategoriesCompleted += (s, e) =>
                    if (e.Error != null)

        return taskCompletion.Task;

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s