Step 3 of 3: Connecting the Web Service

In the previous step you created a Web Service and added a database to your project. In this step you'll continue by linking the Web Service to your application. Note that this step requires ComponentOne Data for Silverlight.

To set up your project, complete the following steps:

1.   In the Solution Explorer, expand the project's node, right-click the project name (for example ComponentOneDataGrid) and select Add Reference from the context menu.

2.   In the Add Reference dialog box, add a reference to the C1.Silverlight.Data assembly and click OK.

3.   In the Solution Explorer, right-click the project name and select Add Service Reference from the context menu.

4.   In the Add Service Reference dialog box click the Discover button. The DataService.asmx file will appear in the list of Services.

5.   In the Namespace text box, change the default value to "DataService" and click the OK button to save your settings and close the dialog box.

6.   In the Solution Explorer, expand the MainPage.xaml node and double-click the MainPage.xaml.cs or MainPage.xaml.vb file to open it in the Code Editor.

7.   Add the following import statements at the top of the file:

      Visual Basic

      C#

8.   Add LoadData(); to the MainPage constructor so it appears like the following:

      Visual Basic

      C#

9.   Add the LoadData and svc_GetDataCompleted methods to retrieve data from the Web Service:

      Visual Basic

      C#

10.  Implement the GetDataService() method by adding the following code:

      Visual Basic

      C#

11.  Implement the BindData() method by adding the following code:

      Visual Basic

      C#

12.  Run your application and observe that the grid appears bound to the Employees table of the Northwind database:

 

 What You've Accomplished

Congratulations, you've completed this tutorial! In this tutorial you created a new Silverlight project, added an Access database, and created a Web Service to bind the C1DataGrid control.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.