.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Articles >> WCF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

WCF RIA Service Tutorial Part -1

Posted By:Dhananjay Kumar       Posted Date: January 16, 2011    Points: 75    Category: WCF    URL: http://www.dotnetspark.com  

This is the 1st part of the series WCF RIA Service Tutorial. In this tutorial we will get a feeling of WCF RIA and see our one application is running on WCF RIA, I am going to walkthrough creating first application through WCF RIA Services.

Learn WCF RIA Service Part #1

It may be bit late but let us learn WCF RIA together. I will be writing many parts on Learning WCF RIA Services.

You can also follow my blog


In this part just to get a feeling of WCF RIA and see our one application is running on WCF RIA, I am going to walkthrough creating first application through WCF RIA Services.

In a Silverlight Data Grid we will fetch and display all the records from Person table of School database using WCF RIA Service.

Creating Project

Open Visual studio and create a new a new Silverlight Application.

Make sure you have checked the Enable WCF RIA Service checkbox.

We will have two projects in the solution

Creating DataModel

Now let us create a DataModel.  I am going to use School database here.

 The first step is to create database. We are going to use School database.  Script of sample School Database copy from here

 Right click on Server Project [web project] and add a new item

Add ADO.Net Entity model from Data tab.

Choose the option generate from Database.  If Database you want to use is listed in drop down the choose that else create a New Connection.

Provide server name and authentication and choose the database.

Either leave default name for connection string in config file or give a unique name.  and after selecting table click finish.

Note: Make sure after creating Data Model you have built the project. This is a important step
Creating Domain Service

Right click on Server Project [web project] and add a new item. From web tab select Domain Service class

Select available Data context class from drop down.  And select Person class from list of tables.

After this step you will get DomainService1.cs class created in the web project.

 There are two things to notice about the class.
1.  Class is inherited from LinqToEntitiesDomainService class
2.  Attributed with EnableClientAccess.

Fetching Data from at Silverlight client

Build the project and add the namespace

Add a Data Grid on design

After adding Data Grid xaml will look like below



At the code behind now we need to fetch the data from Domain service.  For that

1.  Create an instance of Domain service class

2.  Load the entity set to be bind as item source of data grid.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using RIA1.Web;
using System.ServiceModel.DomainServices.Client; 
namespace RIA1
    public partial class MainPage : UserControl
        public MainPage()
            DomainService1 context = new DomainService1();
            LoadOperation loapPerson = context.Load(context.GetPeopleQuery());
            myGrid.ItemsSource = loapPerson.Entities; 

Press F5 to run the application,

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend