RIA Services is a new Microsoft framework for developing n-tier Line of Business (LoB) applications. RIA Services make it easier to build Silverlight applications that communicate with a server, which is the focus of this article. As a developer, RIA Services provides automatic code generation for common scenarios where you need to perform CRUD operations on data and have a consistent model to validate data across tiers. The following sections explain how to get started with RIA Services, specify a data source and a UI, and automatically generate code for CRUD operations. Let me show you the big picture of RIA Services from an architectural perspective first
ASPHostCentral.com is the premier ASP.NET Hosting Provider which supports Silverlight 3 and RIA Services. You can start creating your first RIA Service project online from as low as $4.99/month ONLY! You can check our various Silverlight Hosting Plans by visiting our website directly at http://www.asphostcentral.com
Understanding RIA Services Architecture
RIA Services solves problems in n-tier application design for Silverlight applications by making it easier to serialize and stream objects across a network, sharing common validation among tiers, and automating asynchronous communication. To compare current development practices to what RIA Services offers, consider a common architecture, shown in Figure 1, using Web services to allow a Silverlight application to communicate with the server

Figure 1. N-Tier architecture with Web services
To the left of Figure 1 is a Silverlight control in a browser, which is the presentation tier. Following the network connection to the right, the Web service resides on the server, which is a separate tier where Business Logic Layer (BLL) and Data Access Layer (DAL) code reside; the sidebar, Layers and Tiers, explains the difference between layers and tiers.
LoB application development is very much about managing data properly. In the Web services scenario in Figure 1, you can see how data management must be handled in each tier. Perhaps you have a framework that makes it easier to stream data across the wire, but you still have manual work to do in each tier to manage CRUD operations
Observe in Figure 1 the separate validation code in each tier of the application, because in many cases you can’t make the assumption that presentation tier validation is sufficient. Especially in a Web services scenario, any client can send bad data
A common problem with network communications is timeouts and managing perceived performance in the presentation tier in the face of latency. A common way to handle this is via asynchronous calls where your thread returns to the UI immediately and the application later handles the return thread from the Web service and marshals the call back onto the UI thread to update the screen. There are patterns and framework support for managing this, but you must write the code yourself. The solid line between tiers demonstrates the fact that communication is synchronous by default
“Up to now, developers have been fortunate to have the tools to build sophisticated n-tier architectures easier than earlier generations of software technology. However, this scenario becomes even easier with RIA Services.”
Up to now, developers have been fortunate to have the tools to build sophisticated n-tier architectures easier than earlier generations of software technology. However, this scenario becomes even easier with RIA Services. Figure 2 shows how RIA Services simplifies data management, validation, and communications

Figure 2: RIA Services architecture.
The single Data Objects block in Figure 2 demonstrates that the UI and BLL/DAL tiers use the same objects. RIA Services supports LINQ to SQL, ADO.NET Entity Framework, and POCO out of the box, reducing the amount of work that you must do to move data across the network. Similarly, Validation has a single block, showing that the same validation rules defined in the BLL will be used in the UI. RIA Services build a proxy for the UI layer to encapsulate asynchronous communication, represented by the dashed line between UI and middle tier, freeing you from the extra coding
The rest of this article shows you how RIA Services can help reduce the amount of code you write for n-tier LoB applications, starting with an explanation of how to start a Silverlight project that uses RIA Services
Starting RIA Services in a Silverlight 3 Project
The easiest way to use RIA Services is via the Silverlight Application wizard in Visual Studio 2008. The following steps will walk you through the process of creating a Silverlight application that uses RIA Services. For this article I’ll use a C# project, but you can do the same with a Visual Basic project:
1. Start a new Silverlight application by selecting File | New | and Project. You’ll see the New Project window in Figure 3
2. Select Visual C#, select Silverlight in Project types, and select Silverlight Application in Templates
3. Set Name to RIAServicesDemo, specify the Location where you want the project to reside, and click OK. You’ll see the New Silverlight Application window in Figure 4

Figure 3: New Project window.

Figure 4: New Silverlight Application window.
If you’ve built Silverlight applications before, the New Silverlight Application window in Figure 4 will be familiar. The Host the Silverlight application in a new Web site check box creates a new ASP.NET Web site with sample pages containing the new Silverlight control. You can change the project name to anything you like, but this demo will use the default. This demo will also use the default of ASP.NET Web Application Project as the project type; the alternative being an ASP.NET Web Site project. What’s new, for Silverlight 3, in the New Silverlight Application window is the Link options section. To use RIA Services, you must check the box for Link to ASP.NET server project, which establishes the proper assembly references and any other settings required for using RIA Services. If you forget to check the Link to ASP.NET server project box and change your mind later, you can open the Properties window for the Silverlight project and there is an option called ASP.NET server project link on the Silverlight tab that you can change
4. Click OK to create a new solution with a Silverlight application project and an ASP.NET project, shown in Figure 5

Figure 5: New RIA Services application solution.
A couple items in Figure 5 are worthy of mention: assembly references and Toolbox controls. Notice that the Silverlight project, RIAServicesDemo, includes a reference to System.Windows.Ria; the assembly containing RIA Services types. In addition, you can see several new controls in the Toolbox such as DataForm, DataPager, and DatePicker that are new in Silverlight 3
RIA Services supports multiple types of DAL in your architecture, including LINQ to SQL, LINQ to Entities, or custom.”