Tag Archives: REST

CRM 2011, OData and datajs

UPDATE: FALSE ALARM about batch updates.  Turns out the CRM 2011 OData service doesn’t support batch updatesSad smile.  I just assumed it did because I’ve written .NET/Silverlight clients against the CRM 2011 OData service using a derived DataServiceContext.  DataServiceContext based contexts using the “unit of work” pattern through SaveChanges()/BeginSaveChangesc() and they’ve always “just worked.”  I just confirmed that Batch isn’t the default SaveChangesOption so all this was predicated on a bad assumption on my partSad smile.  Nothing to see here.

What people often call the CRM 2011 REST Service or Organization Data Service is an OData service.  If you go to the libraries section of the OData site and select JavaScript, you will be linked to the datajs CodePlex site.  So what about the CRM SDK OData samples (SDK.REST.js and SDK.JQuery.js)?  It’s probably one of those “six in one hand, half dozen in the other” situations in terms of the shared capabilities of the libraries.  Which API you like better probably boils down to a style preference.  There are some differences in capabilities as well.  The CRM SDK libraries have explicit functions to associate / disassociate records.  One of the things the CRM SDK sample libraries don’t offer is a facility to do batch updates, but datajs does.  This comes in really handy when you want to do a bunch of work client side to some data and send it all at once.  Have a look at the OData Code Snippets.  They also have a full OData API reference.


Consuming REST services using HttpClient

digg_url = “http://blogs.msdn.com/devkeydet/archive/2010/02/08/consuming-rest-services-using-httpclient.aspx”;digg_title = “Consuming REST services using HttpClient”;digg_bgcolor = “#555555”;digg_skin = “normal”;http://digg.com/tools/diggthis.jsdigg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;

If you have a need to consume REST Services from .NET Framework based code, then you should really have look at the WCF Rest Starter Kit.  There is a handy class called HttpClient that is, in my opinion, provides the best / cleanest way to consume REST services at the http level.  Essentially, it gives you the ability to make http calls as easy as:


There is so much more to HttpClient than the little snippet above, including ways to easily hydrate / deserialize the response of the REST service into a .NET types.  You have quite a bit of power / control over the common REST service consumption scenarios.  There’s a nice little blog post over at The .NET Endpoint blog which covers HttpClient.  The BEST starting point, again my opinion, for learning about HttpClient is these two Ch. 9 screencasts by Aaron Skonnard:



Once you’ve watched the screencasts and read the blog post, then you will probably want to learn a bit more about the WCF REST Starter Kit.  Here’s a great overview of the kit (also by Aaron Skonnard):