Visual Studio 2008 SP1 provides an easy way to reference the ADO.Net Data Service (formally code named as Astoria). 

(  Visual Studio 2008 SP1 and Visual Web Developer 2008 SP1 are now available for download. )


The following example uses the Astoria service we created in:


1.       In the same solution, add a new C# website project

2.       Right click the website name, and choose Add Service Reference … menu item

3.       Click Discover button, and click the + sign of the found service provider under “Services” tree, you should get a dialog similar to the following dialog.  Note, this is the same Add Service Reference dialog that we used to add WCF service.

Add web service reference


4.       Click OK.
a) You don’t need to remember “
http://localhost:Port#/websiteDSReflectionProviderCSAddNS/WebDataService1.svc” address, as you can find it later in the auto-generated datasvcmap file under App_WebReferences folder.
b) I left the Namespace as default, you need to generate your own Namespace.
c) ADO.Net Data Service is simpler than WCF service, so there is no use for “Advanced …” button

5.       Add the following code to the page_load function, and run it to see the result for yourself:


   protected void Page_Load(object sender, EventArgs e)




            //Note: this Uri port number is changed randomly in website

            String urlstr = "http://localhost:65110/websiteDSReflectionProviderCSAddNS/WebDataService1.svc";

            ServiceReference1.CellPhoneContainer ctx = new ServiceReference1.CellPhoneContainer(new Uri(urlstr));


            //Most complexed query

            System.Data.Services.Client.DataServiceQuery<ServiceReference1.CellPhone> cellPhones =


            foreach (ServiceReference1.CellPhone c in cellPhones)


                Response.Write(c.ModelName + "," + c.Price + "," + c.Bluetooth + "<BR>");




            //Should not use CreateQuery method with parameter ?$, use Execute instead

            var resultsSorted1 = ctx.Execute<ServiceReference1.CellPhone>(new Uri(urlstr + "/CellPhones?$orderby=Price"));



            var resultsSorted2 = from table1 in ctx.CellPhones orderby table1.Price select table1;



            var resultsSorted3 = ctx.CellPhones.OrderBy(table1 => table1.Price);


            foreach (ServiceReference1.CellPhone c in resultsSorted1)


                Response.Write("URI query: " + c.ModelName + "," + c.Price + "," + c.Bluetooth + "<BR>");



            foreach (ServiceReference1.CellPhone c in resultsSorted2)


                Response.Write("LINQ query: " + c.ModelName + "," + c.Price + "," + c.Bluetooth + "<BR>");



            foreach (ServiceReference1.CellPhone c in resultsSorted3)


                Response.Write("lamnda query: " + c.ModelName + "," + c.Price + "," + c.Bluetooth + "<BR>");



        catch (Exception ex)







For more about ADO.Net Data service, please check “Expose And Consume Data in A Web Services World” in




Visual Studio 2008 SP1 提供了一个简单的引用ADO.Net 数据服务(以前代号 Astoria) 的方式。




1.       在同一个解决方案里,加入一个新的C#网页项目

2.       右击网页项目名称,选择“添加服务引用”的菜单

3.       在打开的对话框中点击发现按钮,然后点击在服务列表中发现的服务旁的加号。这个对话框和加入WCF服务的是一样的。

4.       点击确定。
a) 需要记住 “
http://localhost:Port#/websiteDSReflectionProviderCSAddNS/WebDataService1.svc” 的地址,或者以后可以在引用目录下的自动生成的datasvcmap文件中找到。
b) 对话框中有命名空间的缺省值,你可能需要改成自己需要的。
c) ADO.Net 数据服务比普通的WCF 服务要简单一些,所以不需要使用高级按钮。

5.       将上面的程序加入到page_load函数,看看运行的结果。