Home > ADO.Net Data Services > Introduction to ADO.Net Data Services (Part 1 – Creating a Data Service)

Introduction to ADO.Net Data Services (Part 1 – Creating a Data Service)

ADO.Net Data Services (codename: Astoria) is a feature that allows users to find, manipulate, and deliver data through the use of simple URIs. This allows easy access to data over the web and allows separation of business and data logic. The concept comes from a general programming concept referred to as REST.

As of right now, ADO.Net Data Services is available in an “Extension” to .net 3.5. Eventually it will be part of the .net 3.5 sp1 framework. However, for now, you have to do some extra steps to install it (i.e.: install the asp.net extension preview).

This series of blogs is intended to do a walkthrough of creating ADO.Net Data Services and consuming them in client applications. I have written these blogs as reference material to Code Camp speeches I am doing throughout the D.C/NoVa/Md area. These blogs are not intended to describe the benefits or the why’s of ADO.Net Data Services, they are just intended to show how to work with a simple example.

I will list below the environment setup, that is needed right now, to get ADO.Net Data Services working on your computer.

  1. Supported Operating Systems – Windows Server 2003, Windows Vista, Windows XP
  2. .Net Framework 3.5
  3. Visual Studio 2008 or Visual Web Developer 2008 Express Edition
  4. ASP.Net Extensions Preview –http://www.microsoft.com/downloads/details.aspx?FamilyId=A9C6BC06-B894-4B11-8300-35BD2F8FC908&displaylang=en (PLEASE NOTE: as of today 3/21/2008 the Extensions are the way to use this feature, but soon Microsoft will role this into .net 3.5 sp1. So, if you are reading this blog after .net 3.5 sp1 comes out, you might not have to do this step)
  5. OPTIONAL – SQL Server 2005 and the AdventureWork Database. This is just needed for the example I will be writing about in this blog. This is not needed for ADO.Net Data Services. The backend database is irrelevant to work with Data Service (as long as .net can work with it). The AdventureWork Database is just Microsofts example database and it is easy for me to use to show people how to work with ADO.Net DataServices in this blog.

After your computer is setup correctly you can start building the ADO.Net Data Service. Below I will write up a simple example of leveraging the ADO.Net Data Service, as well as the Entity Framework to display a database in a RESTful manner over a web page.

  1. Open up Visual Stuido 2008.
  2. Click File/New/Project…
  3. Choose a Visual C#/ASP.NET Web Application (use C# for this example, it can be VB or any other language, but I am writing this blog assuming c#)
  4. Delete the Default.aspx that was automatically created.
  5. Right click on the WebApplication project and click Add/New Item…
  6. Choose an ADO.NET Entity Data Model and click Add
    1. The Entity Data Model is another new feature of .net that builds out an entire data access/object model for you.
    2. It is very powerful and we are going to take advantage of some of its features for this demo, but I recommend you looking into it more as it is a great new feature of .net.
    3. NOTE: I am using the Entity Data Model for this example because of how easy it is. However, you can create your own custom objects, with your own custom data access if you want. You just have to make sure the objects implement IQueryable.
  7. A Wizard will come up
    1. Make sure Generate from database is selected and click Next
    2. Create a Connection to your database (if one doesn’t already exist) throug the New Connection… button.
      1. Make sure your Data source is SQL Server
      2. Choose your Server name
      3. Choose your Authentication to the database
      4. Select the AdventureWorks database (note: this will only be there if you have installed it, if it is not there Microsoft makes this database available over the internet).
    3. Click Next
    4. Uncheck Views and Stored Procedures – thus leaving Tables as the only checked entity to use, click Finish.
    5. Congratulations! You just created an entire object model and data access layer, based off your database. It is that easy to work with the Entity Framework.
  8. Right click on the WebApplication project and click Add/New Item…
  9. Choose the ADO.NET Data Service.
  10. Lastly, we need to expose the object we created before (with the Entity Framework) to the web in this new Data Service. To do this we need to do two things. Both of these things are represented in the code block below.
    1. Tell the service which object to use. This is the object we put in the WebDataService<….> inheritence of the class.
    2. Tell the service which parts of the object should be visible. We are going to make * visible (which means everything). This is the line we put in the Intialize Service.
          public class WebDataService1 : WebDataService< AdventureWorksModel.AdventureWorksEntities >
              // This method is called once during service initialization to allow
              // service-specific policies to be set
              public static void InitializeService(IWebDataServiceConfiguration config)
                  config.SetResourceContainerAccessRule("*", ResourceContainerRights.All);
              // Query interceptors, change interceptors and service operations go here
  11.  We have just successfully exposed our data through a DataService. Now you can right click on your svc file and set it as the Start Page. Then you can debug your service (F5) to see what you have created.
  12. A WebPage should come up and you should see xml similar to below:


 NOTE: If you don’t see something similar to what is above there are 3 reasons:

  1. The extensions and all the prerequisites are not installed correctly on your computer
  2. The instructions were either not followed correctly, or I messed up somewhere (it is possible, but I have ran through them a bunch).
  3. You have RSS feeds turned on in your internet browser. If this is the case the webpage will look more like an RSS feed than an XML blob. To turn RSS feeds off go to your tools/options of your browser. Find the Feeds/Settings (this will be different for every browser). Turn off the Automatically marking of feeds when reading feeds (this will be stated differently for every browser).

This is part one of this blog. There will be 2 more parts:
Part 2: Reading and Manipulating ADO.Net Data Services results in the browser
Part 3: Reading and Manipulating ADO.Net Data Services results in a .Net consumer application

Categories: ADO.Net Data Services
  1. rick watson
    April 22, 2008 at 4:29 pm

    just a quick question… where are the GetProducts methods mentioned in the public ilist declaration? thank you.

  2. Greg Galipeau
    April 22, 2008 at 4:58 pm

    Hi Rick. There is no “GetProducts” method in the public list declaration. That is a WebService thing you are thinking of. DataServices expose data through URLs. So, to get the products you would go to something like this in your URL – http://www.ServiceAddressHere.svc/Products. The second part of this series of posts talks about this, so please read the entire series and I think your question will be answered. Plus, the third part of this series talks about how .net client applications can be used to query out to the URLs.

  3. sindhu
    February 24, 2009 at 7:03 am

    Hi i got tlll part-1…cannot traverse into products and products(1)..
    it shows some internet explorer error…
    Wat should i do….

  4. sindhu
    February 24, 2009 at 7:05 am

    HI need a clean explaination of doing further….after part 1
    am not getting the microsoft.data.client.dll in 3.5
    y shoud we browse into it???

  5. Greg Galipeau
    February 24, 2009 at 12:54 pm

    Hi sindu,
    First of all, this blog is a little old. I wrote this when ado.net dataservices was part of the .net 3.5 extensions. Since then, .net 3.5 sp1 has come out and it has been wrapped up into that. I am pretty sure that the steps in the blog still make sense for sp1, but the installing of the extensions I mention in the begining is no longer needed.
    As for your question, I don’t really understand it. Sorry. Could you be a little more clear on what your issue is and what you are asking. If you have actual error messages, that might help also.

  6. sindhu
    February 25, 2009 at 7:33 am

    HI,thanks for ur reply….
    i got the output in xml format…
    but i cant traverse through the table inputs
    for example…
    It shows some Internet explorer error….
    how to resolve this..
    can u help as soon as possible.. 😦

  7. Greg Galipeau
    February 25, 2009 at 1:43 pm

    I cannot help you unless you are more specific. You say you get som Internet explorer error. What is this error?

  8. sindhu
    February 27, 2009 at 12:47 pm

    hi , can u pls help me in resolving this….

    To view Atom (the default format returned by an ADO.NET Data Service) in Internet Explorer, you must first ensure that Feed Reading View is turned off. This can be done on the Content tab of Tools | Internet Options

    but i cant see the feed reading view in settings…
    what should i do
    where should i set this..
    help me pls….

  9. Greg Galipeau
    February 27, 2009 at 1:26 pm

    What version of IE are you using? I am using 7. Here is where I go Tools – Internet Options – Content Tab – Feeds – Settings – uncheck the checkbox “turn on feed reading view”.
    Unfortunately, I can only tell you exactly where it is in IE7, so if you are using a different version, you might have to search around for it.

  10. sindhu
    March 2, 2009 at 9:23 am

    Hi thanks for ur reply….
    I changed the version of IE and it works now.. 🙂
    Can u help me in this also pls…. 😦
    I added the solution of windows application to the web application solution.
    using service reference i created the data source.
    i dragged the customer table and order table in form.
    Am able to see the details of customer and corrseponding orders of the customer when i run the application.(I did through the code)

    In enedit of the customerbindingsource i gave service.savechanges()

    THis shows error for me saying…

    “DataServiceExceptionError is unhandled”
    Wat should i do further….
    Can u help me pls….

  11. Greg Galipeau
    March 2, 2009 at 1:30 pm

    Well, that is actually really hard to debug over comments like this. That is the generic error for data services. I would try wrapping your save call to the data service in try catch blocks and see if you get anything more specific. Or try steppingin to the dataservice while debugging (I haven’t tried this, but it works with webservices). Anyways, I think the only way to figure out your issue is to narrow down the error a little more to get a more specific error messge than that generally one.
    Also, you might want to try out msdn forums for these types of questions. You will get more people chimming in on their thoughts instead of just one person like me.

  12. October 8, 2009 at 2:15 am

    Is it so that it works only with ADO.NET Entity Data Model or will it work with LINQ to SQL as well?

    • Greg Galipeau
      October 8, 2009 at 11:24 am

      It will work with Linq to SQL also. As long as your objects are of IQueryable then they can be returned in ADO.Net Data Services. Linq to SQL meets that criteria. In fact, you can build your own objects if you want as long as they implement that interface.

  1. March 22, 2008 at 6:41 pm
  2. March 24, 2008 at 9:38 pm
  3. March 26, 2008 at 7:41 pm
  4. August 29, 2008 at 10:39 pm
  5. May 26, 2009 at 8:44 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: