Tech Brief

ADO.NET Data Services

Access data in the cloud with REST.

Data access protocols that use HTTP as the transport and adhere to the Representational State Transfer (REST) architectural style are challenging traditional binary and Extensible Markup Language (XML) formats for data-intensive Web applications. The primary characteristic of the REST model is the division of application state and functionality into resources, which are addressable by a Uniform Resource Identifier (URI). Web-based REST resources use HTTP on port 80 or secure HTTP (HTTPS or Secure Sockets Layer [SSL]) on port 443 to pass public or confidential data through corporate firewalls. Instead of describing the location (endpoint) of a SOAP service with a complex Web Service Definition Language (WSDL) file, RESTful services combine a URL with a query string to serve as the endpoint's URI and omit the SOAP envelope.

The Microsoft ADO.NET Data Services Framework, which almost everyone calls by its original "Astoria" code name, is a specialized Windows Communication Foundation (WCF) implementation that adds a RESTful front-end to the ADO.NET Entity Framework.

Astoria uses an HttpWebRequest with the GET method and query-string URIs to expose relational database schema metadata as XML files and data from relational databases as Atom <feed> elements with member entities as <entry> elements. WCF 3.5 adds support for Atom and JSON serialization to WCF 3.0. AtomPub is Astoria's protocol for implementing HttpWebRequest POST (create), PUT (update) and DELETE methods.

ADO.NET Data Services adds a RESTful front-end to the ADO.NET Entity Framework.
[click image for larger view]
ADO.NET Data Services adds a RESTful front-end to the ADO.NET Entity Framework.

Atom Syndication
The use of XML syndication formats -- such as RSS or Atom -- as the wire format for data transfer is rapidly becoming universal for RESTful services. Although RSS engendered the Web's syndication phenomenon, Atom is ascendant because it and HTTP, URI and URL are Internet Engineering Task Force (IETF) standards. RSS, which is owned by the Harvard Law School, isn't extensible, and it's frozen at version 2.0.

Read-Only Atom Syndication Format (IETF RFC 4287) and the later Atom Publishing Protocol (AtomPub, RFC 5023) for creating and updating resources also benefit from widespread public contribution to the standards process. Google Inc. was one of the first to adopt Atom as the feed format for its free Blogger weblog service; Atom 1.0 and AtomPub underlie the widely used Google Data (GData) APIs for Google Services. (GData also supports RSS 2.0.)

Astoria Toolkit
The Visual Studio (VS) 2008 and .NET 3.5 Service Pack 1 (SP1) beta, released in May, integrate Astoria and the Entity Framework with VS 2008, including the Express editions. Clients for .NET 3.5 SP1 Windows or Web form projects can use the DataServiceQuery class from the .NET Client Library for ADO.NET Data Services Framework (System.Data.Services.Client) to translate LINQ to ADO.NET Data Services-better known as LINQ to REST-queries into GET URIs and query strings. For example, http://domain.com/ Northwind.svc/Customers('ALKFI') returns a single-entry feed with customer data for Alfreds Futterkiste and a reference link to a collection of associated Orders entities. The DataSvcUtil.exe tool autogenerates C# or Visual Basic classes that transform the returned Atom feeds into strongly typed entities defined by Common Language Runtime (CLR) classes. The DataServiceContext class enables maintaining state on the client for managing data changes.

Silverlight 2 beta 2 will include an Astoria Silverlight client that's compatible with VS 2008 SP1; installing the current VS 2008 SP1 beta requires removing the earlier Silverlight 2 beta 1 client beforehand.

Services Snap Together
ADO.NET Data Services and ADO.NET Entity Data Model templates make creating simple services easy and quick. Start an ASP.NET Web Application or WebSite file system project, add a new ADO.NET Entity Data Model item, select a database connection from Server Explorer with the Entity Data Model Wizard, choose the tables, views or stored procedures to include and click Finish to create the complete model. Add a new ADO.NET Data Service item, name the service, import the Model Name Entities namespace, replace a couple of placeholders, and press F5 to display in the browser a default list of entities from the tables or views you selected. Astoria-enabling a Web form or Silverlight client takes a bit longer because DataSvcUtil.exe is a command-line code-generation tool.

Data in the Cloud
ADO.NET Data Services has an expansive future; it's destined to become the on-premises counterpart of Microsoft's new Database as a Service initiative, SQL Server Data Services (SSDS). Francois Ajenstadt, director of project management for SQL Server, has said the ADO.NET Data Services and SSDS APIs will become more closely aligned as SSDS's release date nears. An "Astoria Offline" implementation with ADO.NET Synchronization services to SQL Server Compact 3.5 is in the works, but the team hasn't mentioned a release date. You also can expect Astoria -- and SSDS -- to play an important future role in Microsoft's fledgling Live Mesh project, which will support LINQ.

About the Author

Roger Jennings is an independent XML Web services and database developer and writer. His latest books include "Special Edition Using Microsoft Office Access 2007" (QUE Books, 2007) and "Expert One-on-One Visual Basic 2005 Database Programming" (WROX/Wiley, 2005). He’s also a VSM contributing editor and online columnist and manages the OakLeaf Systems blog. Jennings’ Code of Federal Regulations Web services won Microsoft’s 2002 .NET Best Horizontal Solution Award. Reach him at [email protected].

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube