Silverlight 4.0 Hosting :: Developing a Silverlight 4.0 Application Using WCF RIA Service Class Library

By Lance Livingston, on August 29th, 2013

Microsoft Silverlight is a powerful tool for creating and delivering rich internet applications and media experiences on the Web. Its functionality is similar to Adobe Flash, integrating multimedia, graphics, animations and interactivity into a single runtime environment. Silverlight’s initial emphasis was on providing rich media experiences; enabling designers and developers to add rich degrees of interactivity, media and animation to their websites. Later versions extended its capabilities with many new features essential for business application development. As a result there has been an increase in business applications using Silverlight.

We are going to use WCF RIA Service Class Library instead of Siverlight Business Application template. Follow the below steps.

  • Open Microsoft Visual studio 2010 and 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 “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:
02
  • 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:
06
  • 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).
07

The above happens automatically due to the fact that “BusinessLib” project is configured as shown below (automatically configured through VS template):

07-2
  • 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:
09
  • 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:
09
  • 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:
12
  • 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.