Monday, January 25, 2010

Understanding .NET RIA Services (WCF RIA Services) Architecture

I am very new to this interesting technology and I thought to have a bite too. I have seen many Silverlight geeks talking about RIA services and I felt why are people so crazy and all the time discussing the same topic from Cabs to Washrooms.  Only when I tried my hands on this technology only then I realized the potential of  RIA Services.
".NET RIA Services now popular as WCF RIA Services is a service which bridges the gaps between multiple tiers in any Rich Internet Application such as Silverlight. A common problem when developing an n-tier RIA solution is coordinating application logic between the middle tier and the presentation tier. RIA Services solves this problem by providing framework components, tools, and services that make the application logic on the server available to the RIA client."
The 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 roles by integrating with Silverlight components on the client and ASP.NET on the mid-tier.


RIA Services follows a simple end to end pattern for the flow of business logic across the layers. It models a N tier application into a 2 tier application side by side keeping the legacy of N tier applications alive by maintaining trusted boundaries.


The first part is to write a Domain Service class. The application logic resides in this class.
Domain Service Class  surfaces the set of data a client can see, also specifies rules around the data and the operations such as authorization and validation. 
Domain Service Class is stateless i.e. it responds to query requests and change set requests.


The second part of the pattern is to write a client side Data Model which is known as Domain Context class.This class represents the view of what the client can see. It contains lists of objects, one for each type exposed to the client, and it contains a set of load methods that roughly correspond to the queries exposed on the service. These load methods can be used to load objects into the lists. Domain Context class extracts all the changes made to the data at the client side, creates a list of changes and submits it to the Domain Service class for committing. DomainContext is optimized for taking advantage of the stateful environment and helps in binding client side services like Silverlight and WPF.




Domain Services resides on the server and communicates through REST(Representational state transfer) or SOAP(Simple Object Access Protocol) using XML or JSON.
Domain Context on the client is like a proxy which knows the rules and semantics of Domain Service class.


The Domain Service can work with different data sources from relational databases to CLR types to Azure Cloud Data sources.The Domain Service is a reusable and tangible component which can jell with any Presentation Technology to provide data.


RIA Services can be used in developing Rich Internet Applications under multiple scenarios. One of the scenario can be when a single RIA needs to access few domain services in the middle tier. Another scenario might be when multiple RIA need to access a single domain service in the middle tier.
Irrespective of the scenario there always rests a link known as (RIA Service Link) between middle tier and the presentation tier. This is a special kind of P2P(Project to Project) link which helps to generate Presentation tier logic in the middle tier.


In my next post I will talk more about RIA Services Solution Structures and how to create RIA Services through Visual Studio Interface.



1 comment: