Thursday, July 30, 2009

[Tutorial] ADO.NET Data Services
Part 3 – Host & Client Projects

The last part explained how to use the Entity Framework in combination with ADO.NET Data Services. This part shows how to host an ADO.NET Data Services and how to create a proxy to consume it.

  • Open the Host Console project that was created in the first part of the series and add a Reference to the ADO.NET Data Service project

 ADO Data Services - Part 3 - 01

  • In the Main function implement a DataServiceHost object and use as type ExampleDataService

ADO Data Services - Part 3 - 02

  • Add an application configuration file and configure the connection string to the AdventureWorks data source (you may copy the ConnectionStrings section from the WebConfig file of the ADO.NET Data Service project)

ADO Data Services - Part 3 - 03 ADO Data Services - Part 3 - 04

  • Open the Client Console project that was created in the first part of the series and add a Service Reference to the ADO.NET Data Service project (click on Discover), which will auto-generate some proxy classes

ADO Data Services - Part 3 - 03

  • In the Main function implement the proxy class AdventureWorksEntities,and add a function call to a Read method

ADO Data Services - Part 3 - 06

  • Implement the Read method by using a simple LINQ query that retrieves Product data from the AdventureworkEntities proxy and that display the results

ADO Data Services - Part 3 - 07

  • Run the application using as Startup projects the Host and the Client projects and you will get the following output

ADO Data Services - Part 3 - 08ADO Data Services - Part 3 - 09

  • When entering ‘Read’, the ADO.NET Data Service will be queried and a list of all products will be displayed

ADO Data Services - Part 3 - 10


Share/Save/Bookmark

No comments: