Friday, 2 March 2012

Using the CRM web service with Silverlight and Rx - The CRM Methods

Recently, I've been developing a complex Quote tool for our client. This tool allows the user to create sophisticated Quotes with minimal effort and includes all sorts of things like preconfigured kits, automated discounts and translations into different languages. This tool had to work offline within the Outlook client, so there was only one way forward, Silverlight. And with that, a steep learning curve on how to get the most out of Silverlight within CRM 2011.

The first port of call was the MSDN walkthrough needed to connect a Silverlight app to CRM 2011 (available here: This creates your reference to the CRM SOAP web service and a new SilverlightUtility class with some of the helper messages needed.

But, one thing that really stumped me, was how to get the webservice calls to CRM to execute sequential code easily without having events and handlers everywhere, and without destroying the asynchronous nature of Silverlight.

The answer to this was Rx, which allows the developer to create simple (ish) nested code which is then executed on the completion of the asynchronous web service call, and this first blog post sets the foundations of how I used this to communicate with CRM.

I must give credit to David Yack ( who's advice online steered me towards Rx and onto develop this helper class.

First off, you need to follow the MSDN walkthrough to get the Silverlight utility and set up the webservice.

Secondly, you'll need the Rx Extensions for C# (available here: referenced in your project.

Next, we'll need to create our helper class. This class will create the simple methods required to talk to CRM using Rx, through which all calls to CRM will be made: