Developing a Silverlight 4.0 application using “WCF RIA Service Class Library”
By Jag on Dec 29, 2010 with Comments 1
This is a beginner’s (introductory) walkthrough to develop a simple Silverlight 4.0 application using “WCF RIA Service Class library”. This is going to be very similar to what I already explained here:
Developing a basic Silverlight 4.0 application using WCF RIA Services
The only difference between previous article and the current is that, we are going to use “WCF RIA Service Class Library” instead of “Siverlight Business Application” template.
Following are the steps:
- Open Microsoft Visual studio 2010
- Go to File || New Project
- In the “New Project” dialog, select “Silverlight” in the “Installed Templates”
- Within the list of Silverlight templates, select “WCF RIA Services Class Library”
- Provide “Name” as “BusinessLib” and “SolutionName” as “SLBusinessAppWithRiaLibSol” and click on “Ok” as shown below:
- Using “Solution Explorer”, right click on “BusinessLib.Web” project, select Add || New Item
- In the “Add New Item” dialog, select Common Items || Data and select “ADO.NET Entity Data Model”
- Provide name as “EmpMgrDataModel.edmx” and click on “Add” as shown below:
- You will be prompted with “Entity Data Model Wizard”
- Select “Generate from Database” and click on “Next”
- Provide database connection details and make suer that everything is provided/selected/named as follows:
- click on “Next”. You will be provided with list of tables. Select the ones you need, provide the “Model namespace” name and click “Finish” as shown below:
- Rebuild your solution.
- using “Solution Explorer”, right click on “BusinessLib.Web” project, select Add || New Item
- In the “Add New Item” dialog, select Common Items || Web and select “Domain Service Class” as the template, provide the name as “EmpMgrDomainSvc.vb” and click on “Add” (shown below):
- In the “Add New Domain Service Class” dialog, provide “Domain service class name” as “EmpMgrDomainSvc", make sure that “Enable client Access” is selected, select the tables, allow “Enable Editing”, select “Generate associated classes for metadata” and click on “Ok” as shown below:
- Rebuild the solution. Once you rebuild is succeeded, you should see a new folder “Generated_Code” in “BusinessLib” project as shown below (click on “Show All files” if not shown).
The above happens automatically due to the fact that “BusinessLib” project is configured as shown below (automatically configured through VS template):
- Go to File || Add || New Project, select Visual Basic || Siverlight (in Installed Templates), select “Silverlight Application” template, provide “Name” as “SLBusinessAppWithRiaLib” and finally click on “Ok” as shown below:
- In the “New Silverlight Application” dialog, host it in ASP.NET web as shown below and make sure that you uncheck “Enable WCF RIA Services” and finally click on “Ok” as shown below.
- Right click on “SLBusinessAppWithRiaLib.Web” project, go to “Add Reference” and select “BusinessLib.Web” in the list of “Projects” and click on “Ok” as shown below:
- Add a reference to “System.ServiceModel.DomainServices.Client” for “SLBusinessAppWithRiaLib” project as shown below:
- Add a reference to “BusinessLib” project for “SLBusinessAppWithRiaLib” project as shown below:
- Rebuild the solution
- add a “DataGrid” to “MainPage.xaml” as shown below:
- Modify “MainPage.xaml.vb” as shown below:
- Modify “Web.Config” as follows (the entries were copied from App.Config of “BusinessLib.Web”):
- Rebuild all and execute your application. You should see the output as follows:
The solution in this sample was developed using Microsoft Visual Studio 2010 Ultimate Edition with Silverlight 4.0 tools installed. It was not tested in any other edition/version.
The entire source code for this article can be downloaded here:
For this article, I created table structure/data as shown here.
thanks
Jag
Filed Under: Silverlight/WPF
About the Author: Jagadish Chatarji Pulakhandam currently works as a .NET Architect and is responsible for analyzing/designing enterprise-level .NET applications.He has been in the IT field for about 14 years. Apart from Oracle and .NET, he has a good knowledge of developing corporate software and web applications, designing and implementing databases, and working with enterprise reporting software. During his free time, he contributes technical articles to OTN (Oracle Technology Network) and to the family of Developer Shed websites.

















Do you have an example of using this technique and then enforcing forms based authentication/authorization? Specifically, when I use WCF RIA Service Class libraries, I can’t figure out why adding [RequiresRole("RouteStepRead")] makes this fail when the exact same Role works fine if I build the application with a Silverlight Business Application Template. I guess I’m looking for a lesson in how Class Libraries figure out what roles area available and how I can send the proper information along to the service.