I know many posts have been written on this subject by many people, but I am writing this one mostly for myself. I find it very useful to type my thoughts on any subject and create a sample project to help me commit more information to memory. So, here it goes.
What you need to get started.
- Visual Studio 2008 SP 1 (You can use 2010 as well)
- WCF RIA Services Beta for Visual Studio 2008 SP1 (http://www.microsoft.com/downloads/details.aspx?FamilyID=76bb3a07-3846-4564-b0c3-27972bcaabce&displaylang=en)
Here is what needs to be done next.
Create new Silverlight project. To do so just create new project and select Silverlight. Make sure to create a host web site as well.
On the next wizard screen select an option to create new host web site and enable .NET RIA Services.
Now, add new project to the solution, selecting WCF RIA Services Library under Silverlight projects.
Here is what your solution will look like:
Go ahead and delete Class1.cs from both RIAServicesLibrary projects. What you see here are two new project. RIAServicesClassLibrary1.Web will be server side project, the other RIA project is client side. Now you need to establish references. Add a project reference to SilverlightApplication1 and point it to RIASerivcesLibrary1 project. Add a project reference to SilverlightApplication1.Web and point it to RIAServicesLirbary1.Web.
Now you need to create Entity Framework item inside the RIAServicesLibrary1.Web project.
Follow all the step of that wizard, generating a model from the database and pointing to a new or existing server connection. You can select all or some tables from a database.
Go ahead and build your solution now.
Now add another new item to RIAServicesLirbary1.Web project and select Domain Service Class
Select the Entity Framework model you just created in that wizard and select tables you would like to use on the client.
Rebuild the solution once more to generate Silverlight side hidden classes that support RIA Services. You can see that code if you click on Show All Files button in Solution Explorer:
Now, I am going to test the setup by adding the following code to MainPage.xaml.cs. I am going to simulate the login process by getting a specific user from my Users table and checking the password:
public partial class MainPage : UserControl
DomainService1 _context = new DomainService1();
private void Login()
var query = _context.GetUsersQuery().Where(one => one.UserName == "admin");
_context.Load<Users>(query, LoadBehavior.RefreshCurrent, (o) =>
if (o.Error != null)
if ((o.AllEntities.Count() == 1) &&
(o.AllEntities.First() as Users).Password == "admin")
}, null); ;
Next we need to update web.config in SilverlightApplication1.Web project using app.config from RIAServicesLirbary1.Web project as an example. Make sure to paste all appropriate data into correct places:
<?xml version="1.0" encoding="utf-8"?>
<add name="RolodexEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.sql2008;Initial Catalog=Rolodex;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<add name="DomainServiceModule" type="System.Web.Ria.Services.DomainServiceHttpModule, System.Web.Ria, Version=22.214.171.124, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Run the application now to confirm that everything is working properly. In the next post I will explore the subject of updating the data on the server.