Silverlight Application With RIA Service


Microsoft simplifies the integration of n-tier application development in Rich Internet Application by introducing WCF RIA Services. WCF RIA (also called Domain services) is traditional n-tires application pattern, used with RIA such as Silverlight and it can be used as middle tier.

To know more about WCF RIA Service please refer to the following link.

http://msdn.microsoft.com/en-us/library/ee707344%28v=vs.91%29.aspx

Steps for creating such an application are below.

  1. Create New Silverlight Application

    New project >> Select Silverlight Application.

    1.png
     
  2. Check "Enable WCF RIA Services" check box

    2.png
     
  3. Create Entity Data model.

    3.png

    4.png

    5.png
     
  4. Select tables, views and stored procedure from given list to add it to the entity data model.

    6.png
     
  5. Create Domain Service.

    Before adding a new domain service, compile the web project.

    7.png

  6. Map or enable entity(s) with domain service. In the Entities list you get all tables (also called entities) available in the entity model.

      
    8.png

  7. Now build both projects; Silverlight as well as web. After compiling you will have automatically generated code in the Silverlight project which is responsible for communication between Silverlight and the Domain service.

    9.png


  8. The Domain service has many built-in methods for selecting, inserting, updating and deleting the entity(s). You may also add new methods as per your requirement.

In the attached Silverlight project we a create a custom method to get the customer from its id.

public
CustomerMaster GetCustomerFromId(int customerId)
{
    return this.ObjectContext.CustomerMasters.Where(d => d.CustomerId == customerId).FirstOrDefault();
}

After completion of the web project, you may access this method in Silverlight project.

Up Next
    Ebook Download
    View all
    Learn
    View all