Skip to main content

ADO.NET Data Services

In Traditional web applications, you request a page and the the server, process the request, makes some database calls if needed and put your data and HTML together and pass on to the client.This model has now changed with RIA, using AJAX, Silverlight and others

Take for an example a hotel reservation page that uses AJAX for user interactions. Maybe the intital page loads with all available countries in a combo box. and when the user selects a country, all the hotels for that country is retrived through a AJAX call.


Now, this is different form the typical web model, initially by requesting this page, the server send out HTML and presentation logic (javascript in this case for AJAX) to the client. The request for the hotels for a particular country is a pure data call, where only data flows in the form of XML.

This example was just used to demonstrate the change from the traditionl web model, but you would find a lot more pure data calls then just one (like in this case) in real world web applications.

The ADO.NET Data Serveice (formally called Astoria), helps developers in this area, providing a simple but yet a powerful way to expose data centric operations.
Data services, exposes your data as a RESTful services, so that your data could be accessed as a web resource, i.e through URLs.
As RESTful services support the CRUD operations, you can use HTTP verbs like POST to insert data, PUT to update data, GET to retrive data and DELETE to delete data.

for an example, you can access all the hotels of a specific country like this,
http://www.hotelservice.svc/County(SriLanka)/Hotels..

Tthis would retrive all the hotels in Sri Lanka. The Country and Hotel in the above URL are conceptual entites in your data source of your domain.

The data from the data services can be retrived in multiple represnetation,presently the data service framework exposes data in JSON, ATOM and in POX (plain old XML).

Building a ADO.NET data services is simple. Listed below are some of the common steps when creating a ADO .NET data service.


1) Create a Entity Data Model(EDM) representing your data. The EDM was introduced part of the ADO.NET Entity Framework.
2) Create a data service class representing your entites created in the EDM.

So, Lets make this concept more concrete, lets say my database contains two table, Country and Hotel. I can create an EDM model pointing to my database.
Now, my generated model would contain 2 conceptual entities called Country and Hotel.
Next step, I create a data service (called hotelservice.svc ) based on the generated EDM model.
Now I can access all the Countries using the URL
http://www.hotelservice.svc/Country
You can see that I am actually pointing to the entity that is in my EDM model, which in turns points to the Country table.
I can access the Country with the name India like this (country name is my primary key)
http://www.hotelservice.svc/Country(India)

I can list all the Hotels for the country India like this
http://www.hotelservice.svc/Country(India)/Hotel
and so on..

What makes the ADO.NET data services very simple is that, you dont need to write code for each and every operations you provide, think about it, you would have to write a service opeartion, write your SQL query, connect to a database, execute it, get the result set, convert it into a format your client understands and send it back to the client, but with data services, all this is done for you, only things
you might have to do when exposing data in a database would be to create an EDM model and create a data service (just a few line of code, minimum of 2 lines) and the rest is done by the framework for you.

You can expose data that does not inherantly come from databases, by exposing the data to the data service framework through the IQueryable interface (introduced with LINQ).
The point of this artical is just to introduce ADO.NET data services and not to give you an example of a working sample, you can find more about how to create data services here.


What makes data services easy to use is there capabilty to provide common functionalites like filtering,sorting, ordering of data and paging, through request parameters in the url, for an example, If I want all the 3 star hotels in Sri Lanka, I can send out a request like this,
http://www.hotelservice.svc/Country(SriLanka)/Hotels?$filter=Type eq '3star'

The other operations are as easy as this, the framework even provides a parameter called $value, that allows you to retrive only data without the surrounding XML markup.

You can also restrict the types of operations that users can do on the service, like providing user only with read only access to your data.
You can download the CTP version of the ADO.NET here...try it out.

Comments

  1. So thats great I got some idea for the project ...thanks bro

    ReplyDelete
  2. thanks bro, i got some idea ,,,nice work

    ReplyDelete

Post a Comment

Popular posts from this blog

Hosting WCF services on IIS or Windows Services?

There came one of those questions from the client whether to use II7 hosting or windows service hosting for WCF services. I tried recollecting a few points and thought of writing it down. WCF applications can be hosted in 2 main ways - In a Windows service - On IIS 7 and above When WCF was first released, IIS 6 did not support hosting WCF applications that support Non-HTTP communication like Net.TCP or Net.MSMQ and developers had to rely on hosting these services on Windows Services. With the release of IIS 7, it was possible to deploy these Non-Http based applications also on IIS 7. Following are the benefits of using IIS 7 to host WCF applications Less development effort Hosting on Windows service, mandates the creating of a Windows service installer project on windows service and writing code to instantiate the service, whereas the service could just be hosted on IIS by creating an application on IIS, no further development is needed, just the service implementa

The maximum nametable character count quota (16384) has been exceeded

Some of our services were growing and the other day it hit the quote, I could not update the service references, nor was I able to run the WCFTest client. An error is diplayed saying " The maximum nametable character count quota (16384) has been exceeded " The problem was with the mex endpoint, where the XML that was sent was too much for the client to handle, this can be fixed by do the following. Just paste the lines below within the configuration section of the devenve.exe.config and the svcutil.exe.config files found at the locations C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE , C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin Restart IIS and you are done. The detailed error that you get is the following : Error: Cannot obtain Metadata from net.tcp://localhost:8731/ Services/SecurityManager/mex If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. F

ASP.NEt 2.0 Viewstate and good practices

View state is one of the most important features of ASP.NET because it enables stateful programming over a stateless protocol such as HTTP. Used without strict criteria, though, the view state can easily become a burden for pages. Since view state is packed with the page, it increases size of HTTP response and request. Fortunately the overall size of the __VIEWSTATE hidden field (in ASP.NET 2.0) in most cases is as small as half the size of the corresponding field in ASP.NET 1.x. The content of the _VIEWSTATE field (in client side) represent the state of the page when it was last processed on the server. Although sent to the client, the view state doesn't contain any information that should be consumed by the client. In ASP.NET 1.x, if you disable view state of controls, some of them are unable to raise events hence control become unusable. When we bind data to a grid, server encodes and put whole grid in to view state, which will increase size of view state (proportional to the