WCF RIA Services
Overview of WCF RIA Services in Silverlight 4
Microsoft WCF RIA Services simplifies the traditional n-tier application pattern by bringing together the ASP.NET and Silverlight platforms using the power of WCF for communication. WCF RIA Services provides a pattern to write application logic that runs on the mid-tier and controls access to data for queries, changes and custom operations. It also provides end-to-end support for common tasks such as data validation, authentication and authorization based on roles by integrating with Silverlight components on the client and ASP.NET on the mid-tier.
Key Problems Solved
Currently building a Rich Internet Application (RIA) involves a fair amount of plumbing. For a developer familiar with a web application or a 2-tier smart client application, there are additional concepts to deal with including managing state on the presentation tier, working with an asynchronous model and providing good validation capabilities. In addition to writing application logic specific to your domain, you have to think of the two parts of your application spread across tiers and manage the corresponding projects together.
Key Classes: DomainService and DomainContext
WCF RIA Services provides framework and tooling support for some of the common RIA patterns. A RIA developer authors a DomainService to define the application logic on the mid-tier that operates on a set of data classes called entities. RIA Services then generates the corresponding client-side entity proxies and DomainContext class on Silverlight. The generated classes allow a developer to retrieve data, work with it with rich binding and change tracking capabilities and submit a unit of work corresponding to application tasks completed by the end user of the application. The two parts of the application are weaved together in a single Visual Studio solution to simplify iterative development and testing. In addition, a set of common tasks such as validation, authentication and authorization are pre-plumbed and simplified through declarative attributes.
WCF RIA Services in an Architecture
Entities act as containers or data and associated validation information specified as attributes or external metadata. They are obtained via Data Access Layer (DAL) of your choice. Examples include Entity Framework, LINQ to SQL, web services, DataReader, or DataSet.
The DomainService provides higher-level programming constructs by supporting a set of methods that can be used for authoring arbitrary application logic with entities. It also supports LINQ-enabled query methods that allow the presentation tier to formulate flexible queries while executing them most efficiently in the data tier (database or a web-service).
The DomainService supports data modifications through insert, update, delete methods for enabling the “unit of work” pattern and using transactions supported by the Data Access Layer (DAL). It can also contain a set of named update methods to capture change logic specific to your domain such as approving an expense report or cancelling an order.
When network load is a concern, server throttling can be achieved through regulating the per request load on the database server by specifying maximum result limit on a query method.
Endpoint configuration support is included in WCF RIA Services. By default, only binary endpoint will be exposed but we have made it really easy to add additional/different endpoints. OData endpoints are also supported in WCF RIA Services. You can point PowerPivot to a DomainService OData endpoint and analyze data by calling the appropriate query method. This is the first step in lighting up OData with WCF RIA Services.
On the Silverlight presentation tier the DomainContext class is generated for a DomainService. It enables asynchronous calls to the DomainService query methods to load data into EntityCollections (bindable collections of entities). The relationships between entities are also maintained and tracked on the client to significantly simplify the use of rich data models. When the user completes a logical unit of work, the client part of the application can submit the changes in one shot to the mid-tier. The mid-tier then validates the submitted entities and operations and invokes the developer-authored DomainService methods.
Authentication and Authorization
Authentication and role-based authorization attributes may be applied to the DomainService methods to enforce restricted access to the privileged data and operations on the mid-tier. WCF RIA Services enforces the authentication and authorization requirements and ensures that only permitted users/roles are allowed access. The AuthorizationContext class enables you to have more options for implementing custom authorization rules including entity-based authorization.
Validation and MetaData
Validation metadata can be applies to entities, their members, DomainService operations and their parameters. WCF RIA Services copies the validation rules to the client (unless they are designated as server-only rules). It also provides rich validation experience in the UI. Validation is also performed on the client for early detection of violations. The server independently enforces all validations when changes are submitted.
WCF RIA Services includes validation support based on Silverlight 4’s INotifyDataErrorInfo interface. This eliminates the former technique of throwing exceptions in property setters to handle validation. Instead, through INotifyDataErrorInfo support WCF RIA Services enables metadata driven validation as well as some server only validation scenarios.
The task of rich databinding and operations like filtering, sorting and paging is significantly simplified by the DomainDataSource (DDS). It can be used programmatically or through drag-and-drop from the Data Sources window for a rapid application development (RAD) experience. The DDS also supports the ICommand interface in Silverlight 4 for executing commands. DDS also has support for Load, SubmitChanges, RejectChanges, and integrates very nicely into binding in the Visual Studio 2010 designer.
WCF RIA Services Toolkit
Similar to the Silverlight Toolkit, the WCF RIA Services Toolkit will have preview and experimental components. This provides a vehicle to ship components with lower overhead and get feedback while keeping the more mature components in the product.
Performance and Reliability
Key improvements have been made to optimize performance across all areas of WCF RIA Services. One such improvement is with optional count queries which are only executed when needed. WCF RIA Services has been enhanced to provide increased resilience, especially with server side components.
WCF RIA Services continues to be a part of Silverlight 4 Tools. The MIX 2010 build of WCF RIA Services will continue to support bin deployment and medium trust scenarios. It also supports server-only installation option, without the development tools, if desired. LINQ to SQL support and ASP.NET DomainDataSource (but not the Silverlight DomainDataSource) has moved to the toolkit
The build of WCF RIA Services released at MIX 2010 will require .NET 4, Visual Studio 2010, and Silverlight 4. The PDC 2009 drop of WCF RIA Services is the last build that is targeted purely for developing for .NET 3.5 SP1, Visual Studio 2008, and Silverlight 3. The newer WCF RIA Services drops significantly benefit from and rely on the work done in .NET 4, Visual Studio 2010, Silverlight 4. This is a cost-benefit tradeoff in favor of longer term needs over near term expediency.