SharePoint 2010 and the upcoming Dynamics CRM 2011 are two of Microsoft's premier products that are leveraging the new Open Data protocol,or OData. At C5 Insight, we focus on SharePoint and CRM, so we're excited about diving into OData and finding ways to use it to enhance our clients' investments in these systems.

OData is an open-source standard for performing read, create and update operations using nothing more than querystring parameters appended to a URL. A RESTful architecture, it's the evolution of Microsoft's ADO.NET Data Services. Data sources like SharePoint lists and CRM tables can be enabled for OData access using the .NET Framework 4's Windows Communication Foundation.

OData uses standard HTTP messages (GET, PUT, POST, and DELETE) combined with the OData syntax to make it easy to connect web-based applications. To use OData, you address the data service's endpoint. This is essentially a URL, something like www.foo.com/mydata.svc. Browsing to this address would bring back an XML feed that you could read in your browser or reference in code.

Inside each data service endpoint will be collections or sets of data. You can think of them as the lists or tables. For example, there might be a "documents" set. So if you were to browse to foo.com/mydata.svc/documents you'd get an XML feed that contained the document data. OData endpoints also provide access to metadata. The standard way to access this would be to browse to the data service endpoint and then add the /$metadata parameter (foo.com/mydata.svc/$metadata).

To query a data collection or add or update records, you add the query parameters. OData has a syntax for this. A simple example is to select the top five records: $top=5 (foo.com/mydata.svc/documents?$top=5). You can combine query parameters as well, so you can do more complex queries.

In Microsoft Dynamics CRM 2011, each organization will have its own OData service address, and each entity will be represented as a "set" under the OData service. The URIs for CRM 2011's OData service look like this:

  • The main OData service: http://crmserver/orgname/xrmservices/2011/organizationdata.svc
  • The metadata URI: http://crmserver/orgname/xrmservices/2011/organizationdata.svc/$metadata
  • Accessing the Account data set: http://crmserver/orgname/xrmservices/2011/organizationdata.svc/AccountSet
  • A query that returns the account number and city for an account named "Advanced Components": http://crmserver/OrgName/xrmservices/2011/organizationdata.svc/AccountSet?$select=AccountNumber,Address1_City&$filter=Name eq 'Advanced Components'

Here's the XML the query above would return:

References: