Build a Simple Application with .Net RIA Services (Silverlight 3) – Part 1

4 באפריל 2009

Build a Simple Application with .Net RIA Services (Silverlight 3) – Part 1

This is the first post in a series of posts about building applications with Microsoft .Net RIA Services and Silverlight 3. In this post I will create a new application, create a simple data model and use the Domain Service and Domain Context to retrieve data and bind it to a DataGrid.

Before you start, make sure you have Silverlight 3 Beta and .NET RIA Services March 2009 Preview installed, and you have already installed and configured SQL Server. In this sample I am using the Bank Schema I’ve used in the past.

Create a Silverlight Navigation Application

Create a new Silverlight Navigation Application.

Walkthrough .Net RIA Services Silverlight 3

After you click OK, the New Silverlight Application Dialog is shown. Click OK again to create an ASP.Net project that links to the new Silverlight Application.

Walkthrough .Net RIA Services Silverlight 3 

A new solution is created. Notice the new assemblies that the Silverlight project is referencing, and notice the new assemblies among them.

Walkthrough .Net RIA Services Silverlight 3

Build a Domain Service

Add a new Data Model to your server side project (BankApp.Web). This data model can be a LINQ to SQL model, an Entity Data Model, or you can use any other business object representation.

In this sample I am using a LINQ to SQL data model based on the Bank Schema.

Walkthrough .Net RIA Services Silverlight 3

Make sure to build the project so that Visual Studio will generate the data classes and data context before the next step.

Add a new Domain Service. Add a new Item to the server project, and select the Domain Service template in the Web category.

Walkthrough .Net RIA Services Silverlight 3

After you add this item, the New Domain Service Class Dialog is shown. Select the Data Context (BankDataContext in this sample), select the entities you want to expose and whether you want to allow editing and click OK.

Walkthrough .Net RIA Services Silverlight 3

Walkthrough .Net RIA Services Silverlight 3This adds the BankDomainService.cs that contains the code that exposes the data to the client, and BankDomainService.metadata.cs that contains additional metadata, mostly for presentation and validation.

A few references were also added: System.ComponentModel.DataAnnotations, System.Web.DomainServices, System.Web.DomainServices.Providers and System.Web.Ria.

In addition to that, a new Http Handler was added to the web.config file.



  <add path="DataService.axd"


      type="System.Web.Ria.DataServiceFactory, System.Web.Ria, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"

      validate="false" />


Walkthrough .Net RIA Services Silverlight 3Build the solution. This executes a build target the generates the client side code that is required in order to consume the Domain Service. If you click the Show All Files button for the client application, you’ll notice the generated code.

Display Domain Data in the Application

Add a DataGrid Control to the client application. To do that, add a reference to System.Windows.Controls.Data.dll that contains the DataGrid Control.

Then, open the Views\AboutPage.xaml and add an xmlns prefix to the CLR namespace of the DatGrid.

<navigation:Page x:Class="BankApp.HomePage"


Add the Xaml markup for the DataGrid Control:

<Grid x:Name="LayoutRoot" Background="White">



    <StackPanel Style="{StaticResource ContentTextPanelStyle}">



    <data:DataGrid MinHeight="200" x:Name="dataGrid">




Handle the Loaded Event of the Page. First, Add a method to handle the Loaded event of the page.

<navigation:Page x:Class="BankApp.HomePage"


    Title="HomePage Page">

In the method that handles the event, use the client Domain Context to retrieve data from the service and bind to the DataGrid.

private void Page_Loaded(object sender, RoutedEventArgs e)


  BankDomainContext context = new BankDomainContext();

  this.dataGrid.ItemsSource = context.Customers;



Now, run the application and let it go and retreive the data and present it in the DataGrid.

Walkthrough .Net RIA Services Silverlight 3

In this post I created a new application, created a simple data model and used the Domain Service and Domain Context to retrieve data and bind it to a DataGrid. In the next post I’ll explore more controls that ship with the .Net RIA Services.


Add comment
facebook linkedin twitter email


  1. Braden11 באפריל 2009 ב 1:04

    Great post. I look forward to part 3

  2. HenkB1 במאי 2009 ב 23:48

    How to do this when you have Oracle as database?

  3. Jonathan15 במאי 2009 ב 19:40

    Anybody know how to handle Enums with RIA Services?

  4. Tito22 במאי 2009 ב 16:21

    I try to execute your SQL code and I've got:
    "Msg 208, Level 16, State 1, Line 3
    Invalid object name 'Bank.dbo.Customers'."
    Is it right? Where I can find the Bank database ?

  5. jak szybko schudnac11 ביולי 2009 ב 10:31

    Ciekawy artykul, bede tu teraz wpadal czesciej, pozdrawiam bzerwiusz

  6. ewart18 ביולי 2009 ב 5:43

    Is it possible to have seperate (multiple) data classes working with silverlight RIA? things work fine when it's all int he same project but when I create a seperate data project in the solution I can't retrieve data from it at all.

  7. jrf3 בספטמבר 2009 ב 20:21

    context.LoadCustomers() not defined?!?!?!

Comments are closed.