.NET RIA Services Overview
page 2 of 4
by Sergey Zwezdin
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 21347/ 38

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.


View Entire Article

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-2024 ASPAlliance.com  |  Page Processed at 2024-04-24 10:02:55 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search