In this part, I will continue with the implementation of the data service using ADO.NET Data Services, and if you want some background, please see the previous parts:
Part 1 was a general introduction Part 2 outlined the architecture (tiers, etc) Part 3 showed the benefit of loosely coupled tiers (distribution, cloud, etc) Part 4 started the implementation by creating the entity data model (using ADO.NET Entity Framework) The implemented architecture is published on CodePlex in a project called KISS Architecture, and this means that you can access the full source code as well as discuss it, come with suggested improvements, etc. As I walk you through the creation of the architecture, I suggest you keep the source code handy to check out more details.
Now it's time to publish the entity data model (OrderModel.edmx) that we created in the last part (4) of this blog series, and that is done by adding an "ADO.NET Data Service" named OrderDataService.svc to the data tier assembly, Kiss.Data. The modifications necessary to this service class is trivial, and involves specifying the type of the data model (object context, in my case OrderEntities) and making the complete model available to anyone. The resulting code looks like this:
namespace Kiss.Data
{
public class OrderDataService : DataService<OrderEntities>
{
public static void InitializeService(IDataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.All);
}
}
}
Amazing as it sounds, the data tier is now ready to be used, and we can start querying the database through the newly built data service. For example, if we go to http://localhost:1111/OrderDataService.svc/CustomerSet('ALFKI'), we get the following result (somewhat simplified)...
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<entry xmlns="http://www.w3.org/2005/Atom">
<id>http://localhost:1111/OrderDataService.svc/CustomerSet('ALFKI')</id>
<title type="text" />
<updated>2008-11-25T02:24:45Z</updated>
<author>
<name />
</author>
<link rel="edit" title="Customer" href="CustomerSet('ALFKI')" />
<link type="application/atom+xml;type=feed" title="Orders" href="CustomerSet('ALFKI')/Orders" />
<category term="Kiss.Data.Customer" />
<content type="application/xml">
<properties>
<CustomerID>ALFKI</CustomerID>
<CompanyName>Alfreds Futterkiste</CompanyName>
<ContactName>Maria Anders</ContactName>
<ContactTitle>Sales Representative</ContactTitle>
<Address>Obere Str. 57</Address>
<City>Berlin</City>
<Region null="true" />
<PostalCode>12209</PostalCode>
<Country>Germany</Country>
<Phone>030-0074321</Phone>
<Fax>030-0076545</Fax>
</properties>
</content>
</entry>
...and this allows us to query the complete data model through a RESTful interface. Note that you may have to turn off the automatic feed formatter included in Internet Explorer 7 to see the resulting XML (in ATOM format), and you do that by selecting Tools > Internet Options > Content > Feeds Settings, and uncheck "Turn on feed reading view".
In the next part, I will start implementing the middle tier.