Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Expand]Controls and Libraries
 [Collapse]Common Features
  [Expand]Data Binding Common Concepts
  [Expand]Data Source Wizard
  [Expand]Expressions
  [Expand]Behaviors
  [Expand]Application Appearance
  [Expand]Filtering UI Context
  [Expand]High DPI Support
  [Collapse]Scaffolding Wizard
   [Expand]Overview
   [Collapse]Data Access Layer
     How To: Generate Data Access Layer with Entity Framework Database First
     How To: Generate Data Access Layer with Entity Framework Code First
     How To: Generate Data Access Layer Based On Data Provided By a WCF Service
   [Expand]Generating an Application
  [Expand]Formatting Values
   HTML Text Formatting
  [Expand]Menus
  [Expand]Tooltip Management
  [Expand]Saving and Restoring Layouts
   Clipboard - Copy Data and Formatting
   Version Compatibility: Default Property Values
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How To: Generate Data Access Layer Based On Data Provided By a WCF Service

In this example you will create a Data Access Layer that works with the WCF Service, which retrieves data from a remote database.

  1. In Visual Studio, go to "File | New | Project" or press CTRL+SHIFT+N to create a new project. Select the "Blank Solution" template to create a solution with no projects.

  2. Right click the solution in Solution Explorer window, then click "Add | New Project...". Find the "ASP.NET Empty Web Application" template and click OK. You will need this project to emulate the server that exposes data for your application.

  3. You now require an Entity Framework Data Model that represents data tables and views from the sample "Northwind" database. To add this Data Model, follow steps described in the How To: Generate Data Access Layer with Entity Framework Database First tutorial, starting from step two.

  4. After your Data Model is ready, you can proceed to adding a WCF Data Service that will establish a connection to the database and provide access to its data. Before you do so, go to Visual Studio's "Project | Manage NuGet Packages..." menu and install the WCF Data Services EntityFramework Provider package. This one allows you to use WCF Data Services with Entity Framework 6 and higher.

  5. In the Solution Explorer window, select your ASP.NET project and press "CTRL+SHIFT+A" to add a new item. Search for the "WCF Data Service" item, then click "Add".

  6. Open the .svc file added to your project and inspect its code. Notice that Visual Studio suggests you add the data source class name manually.

    Since your Data Model was generated with Entity Framework 6, the data service should inherit the EntityFrameworkDataService<Northwind2010Entities> class.

  7. You now have the server side ready, so add a blank WinForms project to your solution. Once the project is added, right-click it and select the "Set as StartUp Project" option.

  8. Right-click your project in the Solution Explorer window and choose the "Add Service Reference" menu item.

  9. In the "Add Service Reference" dialog that pops up, click the "Discover" button to browse for existing WCF Data Services. Make sure your service URL appears in the "Address" field, then click OK to finish.

Expanded What's Next?

Congratulations, you have created a sample Data Access Layer with data provided by a WCF Service! Check out other Data Access Layer tutorials or proceed to generating an application based on this layer.

How would you rate this topic?​​​​​​​