Data Access has been discontinued. Please refer to this page for more information.

Adding Service Reference and Loading Data

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

In this task, you will add a service reference to the SofiaCarRental plain service and you will learn how to load data.

Adding Service Reference

To add a WCF Plain Service reference to the project:

  1. Right-click the Silverlight client project, select Add Service Reference, and then click Discover. This displays the SofiaCarRentalWCFPlainService that you have created in the previous task.
  2. In the Namespace text box, type SofiaCarRentalWcfPlainService, and then click OK.

    This adds to the project a new code file that contains the data classes which are used to access and interact with plain service resources as objects. The data classes are defined in the default namespace of the client application.

Loading Data

To load data in the Silverlight client application:

  1. Open MainPage.xaml.
  2. From the Toolbox, drag a DataGrid control to within the Grid element in XAML view. Name the DataGrid CustomersGrid as shown in the following XAML.

    <UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
       <Grid x:Name="LayoutRoot"
           <data:DataGrid Name="CustomersGrid" />
  3. Open the code-behind for MainPage.xaml.

  4. Add code to instantiate the service client, retrieve customers and bind the results to the DataGrid, as shown in the following code.

    using System.Windows.Controls;
    using SilverlightOpenAccessIntegration.SofiaCarRentalWcfPlainService;
    namespace SilverlightOpenAccessIntegration
       public partial class MainPage : UserControl
           private SofiaCarRentalWCFEndPointServiceClient serviceClient = 
               new SofiaCarRentalWCFEndPointServiceClient();
           public MainPage()
               serviceClient.ReadCustomersCompleted += serviceClient_ReadCustomersCompleted;
           void serviceClient_ReadCustomersCompleted( object sender, ReadCustomersCompletedEventArgs e )
               if(e.Error == null )
                   this.CustomersGrid.ItemsSource = e.Result;
    Imports SilverlightOpenAccessIntegration.SofiaCarRentalWcfPlainService
    Partial Public Class MainPage
        Inherits UserControl
        Private serviceClient As New SofiaCarRentalWCFEndPointServiceClient()
        Public Sub New()
            AddHandler serviceClient.ReadCustomersCompleted, AddressOf serviceClient_ReadCustomersCompleted
        End Sub
        Private Sub serviceClient_ReadCustomersCompleted(ByVal sender As Object, _
            ByVal e As ReadCustomersCompletedEventArgs)
            If e.Error Is Nothing Then
                Me.CustomersGrid.ItemsSource = e.Result
            End If
        End Sub
    End Class
  5. Run the application. You should see a data grid that is similar to the following.