The Open Data Protocol (OData) is quickly becoming the format of choice when it comes to exposing data. The growing number of client side libraries and all the new features from WCF Data Services is what makes the developers switch from proprietary (Custom REST APIs, SOAP, Binary Formats etc…) to OData.
The simplest way to expose your data as OData is by using the WCF Data Services, which currently comes with a couple of out of the box providers (EF, Reflection etc…). Each provider requires it’s own data model and if you have made XPO your ORM of choice, switching to another model is out of the question. Adding an additional data layer is not something you would want to do either, maintaining more than one is rarely a good practice.
The cool thing about the WCF Data Services is that you can plug in custom providers. A provider for XPO can be downloaded from CodePlex. We’ll develop it together in this series of blog posts, but first, I want to show you how easy it is to expose your XPO model using the XPO Data Service Provider.
Step 1: Have your XPO Model Ready
For demonstration purposes my persistent objects are mapped to the Nwind access database. I used the Add New Persistent Classes Wizard to generate mine.
public class Customers: XPLiteObject {
string fCustomerID;
[Key]
[Size(5)]
public string CustomerID {
get { return fCustomerID; }
set { SetPropertyValue<string>("CustomerID", ref fCustomerID, value); }
}
...
}
public class Products : XPLiteObject {
int fProductID;
[Key(true)]
public int ProductID {
get { return fProductID; }
set { SetPropertyValue<int>("ProductID", ref fProductID, value); }
}
...
}
Step 2 : Add a new WCF Data Service to your project

public class Nwind : DataService< /* TODO: put your data source class name here */ >
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
// config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
// config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
}
Step 3: Add a Reference to DevExpress.Xpo.Services.v10.1.dll
Step 4: Configure your WCF Data Service
[XpoConnectionString("Nwind")]
public class Nwind : XpoDataService
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
}
File: Web.config
<connectionStrings>
<add name="Nwind" connectionString='Provider=Microsoft.Jet.OLEDB.4.0;Data Source="nwind.mdb"'/>
</connectionStrings>
And that’s it! We can now explore our data using a number of different clients that support OData or simply view the feeds in the browser.
What’s Next?
Cheers
Azret