OData (Open Data Protocol) is
a protocol on top of HTTP, based on REST architecture, that allows remote edition and use for different
Web, Mobile, etc…). So one can use Linq to request data from a client interface.
With WCF RIA Services, it becomes possible to
expose your own data easily. When you add a DomainService, you must check the box
“Expose OData endpoint” and the selected tables will be exposed. In our
example, we will expose the Customers and Orders tables from Northwind
Checking the box brings two important modifications to our code:
In the DomainService,
now each parameterless methods have a specific tag :
[Query(IsDefault = true)]
In the Web.Config, an “endpoints” is added in the
domainServices area :
Version=184.108.40.206, Culture=neutral, PublicKeyToken=31bf3856ad364e35″
Now you can compile, run the application and query in a browser the
following URL (which is built like that):
N.B : if the application name and/or the DomainService name contains dots
“.”, you must replace them by dashes “-“.
In our example the correct URL is: http://localhost:2321/RIAOData-Web-NorthwindService.svc/OData/
At the end, we can see all the tables we had selected before.
If you want
to consult the data from a specific table, Customers for example, you can just
complete the URL with the same table name:
The data have been formatted like for ATOM, the browser tries to display it
like a RSS feed. So with a right-click in the browser page, you can select the
option “View Source” to see the Customers data:
wants to practice, it can use the OData website where a lot of exposed data can
be found. A feed list is available on the OData website.