Showing posts with label rx. Show all posts
Showing posts with label rx. Show all posts

Wednesday, May 18, 2011

WCF + Silverlight + Rx (reactive extensions)

Saw a really nice article on using Reactive extensions with silverlight + wcf : http://abovetheblue.blogspot.com/2010/03/reactive-extensions-silverlight-and-wcf.html

Basically you need to use

  • Observable.FromEvent
  • Take(1) ... to automatically unsubscribe from the call. 
  • Now just make the standard WCF call. 
i.e.: 

public Page()
{
    InitializeComponent();

    CustomersServiceClient client = 
        new CustomersServiceClient();
    IObservable<IEvent<GetCustomersCompletedEventArgs>> observable =
        Observable.FromEvent<GetCustomersCompletedEventArgs>(
            client, "GetCustomersCompleted"
        ).Take(1);

    observable.Subscribe(
        e =>
        {
            if (e.EventArgs.Error == null)
            {
                var customers = e.EventArgs.Result;
                dg.ItemsSource = customers;
            }
        });
    client.GetCustomersAsync();
}

I can think up a nice clean code generator that will make WCF calls with neat error handling. Till then.

Enjoy!

Sunday, April 10, 2011

Rx (Reactive Extensions) Video Tutorials

Rx is meant to provide simpler asynchronous application design. These are the video tutorials I could find on Channel 9. I am more interested in the silverlight / WPF usage of this framework:

Writing your first Rx Application : a taste of Rx
DevCamp 2010 Keynote - Rx: Curing your asynchronous programming blues : the best intro
Kim Hamilton and Wes Dyer: Inside .NET Rx and IObservable/IObserver in the BCL (VS 2010)
Wes Dyer and Jeffrey Van Gogh: Rx Virtual Time

Rx Update :  Async Support


From Silverlight.net: 
Asynchronous programming with Rx : by jesse liberty (nice to get a taste of it)


Incomplete:
Reactive Extensions API in depth: intro