.NET RIA Services Overview
 
Published: 27 Oct 2009
Abstract
This article provides a detailed overview of .NET Rich Internet Applications (RIA) services. After a brief introduction, Sergey analyzes the concept with the help of an ADO.NET Entity Framework application along with relevant source code and screen shots.
by Sergey Zwezdin
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 22185/ 65

Introduction

Observing tendency in application development, you can see a clear regularity which shows that a lot of applications have being developed in Internet instead of the desktop way. This tendency is taking place in the last years because of the opportunity to create more interactive web applications. Evolution of JavaScript, Silverlight, Flash, etc. makes it possible. Now we see that many web applications do not receive a personal page when you access it, but load additional data thanks to more web server references. Such an approach allows us to avoid page reloads. So, web-based applications are considered more interactive and can provide more responsive interface. This class of applications is called Rich Internet Applications (RIA).

Without a doubt, RIA is a very perspective direction. These applications can cover a large number of scenarios that have previously been under force of desktop once only.

However, there is a serious problem during the process of building Rich Internet Applications. To develop Rich Internet Application you should do a big work - develop web services to access business scenarios, develop a user interface (Silverlight, Flash, JavaScript) and connect it with a server platform. There is a special mean when we are talking about complex corporate applications.

This problem is partly resolved in a new program platform .NET RIA Services. It is the topic of the given article.

The conceptual solution

As it has already been said, one of the main problems in Rich Internet Applications developing is the laborious process. Working under an application, it is required to implement several different levels to allow the whole application to start working. There are two main levels: business logic on a server side and user interface on a client one. As a rule, these two parts together implement any business scenario. In most cases, separate existence of these two mechanisms is not meaningful. Actually, they supplement each other in the course of work. Thus, it is clear that a part of the code will be duplicated on both client and server sides during a similar mechanism of realization. This problem can be partly solved thanks to entering a special function in general assembly. But it is difficult to do it for web-applications. In most cases, this is a reason for developers' code rewritings.

In NET RIA Services this problem is solved with the flowing way. A data model and level of business operations are created on a server side. All necessary operations are implemented and various rules to work with them are set in a class with business logic. A class, which implements business operations, accesses to a data model to get and update data in a source.

As a client and server are usually located on different computers, so a platform for service interaction is required. This platform should be user-friendly and demand minimum efforts in service implementation. These services should be used to work with data.

Thanks to these conditions, it becomes clear that it is more convenient to use ADO.NET Data Services platform. This tool allows us to build web-services data access based on REST approach.

So, access to a class with business logic is granted on a server side with help REST interface. By default, this support is built in .NET RIA Services. However, a client support is also required to support application work. A client should be able to access various data and business operations on a service side. In this case, it is very important that this access should be completely transparent in terms of a client code. This is the reason to generate a class that allows us access to service thanks to REST interface on a client side when there is any changes in a business logic on a server side. As a result, any addition of new business operations on a server side makes them available on a client one automatically.

Thus, the conception of Rich Internet Applications development is that business logic is developed once and used on a server and client simultaneously. Any changes in logic on a server side determine the changes on a client side automatically. Any changes are applied on a client. It is brought into effect thanks to an autogenerated code.

Figure 1: Development of Rich Internet Applications

The simple application is constructed on base of .NET RIA Services.

Let us create the small application based on .NET RIA Services after a small theoretical review. For this purpose, let us use ADO.NET Entity Framework which will represent itself as a data source. Also, we will need SQL Server with installed Northwind database.

After adding a data model into a project, it is necessary to add Domain Service Class there. 

Figure 2: Creation of Domain Service Class

This class is a class of business logic. After you add it in the project a window where you should choose a data source is displayed. The Visual Studio IDE recognizes all data sources automatically and allows you to make a choice.

Figure 3: Adding of domain class

Working under creation of a class with business logic you can tune various options. For example, it is possible to specify opportunity to edit chosen collections or necessity to generate a metadata class. A metadata class is needed to determine each entity behavior. For example, with its help it is possible to set rules to validate each field.

The following code will be generated after class creation.

Listing 1 - Sample of domain class

[EnableClientAccess()]
public class NorthwindDomainService : LinqToEntitiesDomainService<NorthwindEntities>
{

You see that this class is an inheritor of LinqToEntitiesDomainService<> class. Such a type of a parent is specific for business classes which work with ADO.NET Entity Framework. There are also classes to work with LINQ to SQL, etc. If you need to realize logic of work with a custom-source it is required to create a DomainService class inheritor.

Availability of EnableClientAccess attribute says that code should be generated on a client for this class. If the attribute is unavailable, the code will not be generated. Indeed, if you open a client project and display all files in a folder then you see a folder which contains a generated code.

Figure 4: Displaying folder with generated code at client

In the generated file on a client there are descriptions of all entities which are defined in the main class and class-context definition. The context is necessary to bind a user interface on a client and service. Actually, it is a proxy-class which broadcasts queries to data collections on a service and processes results.

After these simple actions most of application is ready. Now it is necessary to bind data with a user interface. For this purpose you should use generated class-context. This class contains references to data collections available on a service side. These collections will contain data as soon as a data load method will be executed. For example, to display Customers collection in element DataGrid it is possible to use the following code.

Listing 2 - Loading data from service

<span style='background:white'>var context = new NorthwindDomainContext();</span>
<span style='background:white'>Grid1.ItemsSource = context.Customers;</span>
<span style='background:white'>context.LoadCustomers();</span>

For every collection that is in a class with business logic on a service side, a similar method for data loading will be generated. For example, you can display the same way you do Employees' collection contents.

Listing 3 - Loading data from service

<span style='background:white'>var context = new NorthwindDomainContext();</span>
<span style='background:white'>Grid1.ItemsSource = context.Employees;</span>
<span style='background:white'>context.LoadEmployees();</span>

It is important to remember that if a method of data loading is not called, a collection will not contain any values because there is a need to call this method every time when it is necessary to obtain data from a server.

You can also create a query over received data. It can be realized thanks to LINQ query creation.

Listing 4 - The query to service

var context = new NorthwindDomainContext();
Grid1.ItemsSource = from empl in context.Employees
                    where empl.LastName.Contains("a")
                    select empl;
context.LoadEmployees();

Thanks to small efforts to create business logic, we have a constructed Rich Internet Application. At the same time, we did not create services of ADO.NET Data Services separately, did not adjust them and did not create queries to the necessary data. The .NET RIA Services platform has executed all these actions within itself.

Data sources

Working under the application programming we saw, that ADO.NET Entity Framework was a data source. We also saw that, at platform level, the class containing business operations was allocated. Such allocation in a separate class allows us to abstract certain client technologies and data sources. So, data sources can be datastores based on POCO, services and datastores with custom logic. Similar reasoning is fair for a client part. The .NET appendix (Silverlight, WPF, etc), JavaScript code, services, etc. can be a client for such service. In fact, building business logic once means it can be used repeatedly.

Figure 5: Overview of concept of .NET RIA Services

Besides that, allocation of a central object with business logic that does not depend on representation and data source makes it possible to build unit tests for it and to develop such applications in Test-Driven-Development style.

Conclusion

In this article we have considered problems of construction Rich Internet Applications and considered a .NET RIA Services platform which helps to simplify this process essentially. Certainly construction of such applications is not reduced to simple data acquisition from service. In the given article examples have been intentionally made simple. It is necessary to better understand a general concept. However, .NET RIA Services allows us to create various scenarios where other business operations take place. An important point is that a class containing business logic is independent.

So, it is possible to say that in the near future development of Rich Internet Applications will become simpler and this type of application will enter into our life even more.



User Comments

Title: Lead Developer   
Name: Don B
Date: 2009-11-06 7:50:37 AM
Comment:
Perhaps George shouldn't start drinking before Noon. I wonder how many languages he can intelligently converse in or if he is capable of adding anything meaningful to the actual topic.
Title: Lead Programmer   
Name: George Wilson
Date: 2009-11-02 11:56:02 AM
Comment:
This article is poorly written. It reads as if Yoda wrote it, "Problem resovled in new platform it is...mmmm...yes!"

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-11-26 11:28:00 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search