Dotneteers.net
All for .net, .net for all!

Discovering Silverlight 3 – 5 minutes of RIA Services

In July, I gave a talk about Silverlight 3, and even though the entire session was 3 hours (and two bottles of mineral water) long, I only had 5 minutes for RIA Services. So, my only goal was to shed some light on the topic, and scratch the surface of the surface… Let me sum that part up here. Disclaimer: this is just a quick blog post answering a forum question, by no way a proper RIA Services intro.

The official “What is .Net RIA Services” summary from the download page:

“Microsoft .NET RIA Services simplifies the traditional n-tier application pattern by bringing together the ASP.NET and Silverlight platforms. 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. “

The way I like to put it:

.NET RIA Services simplifies communication between the client and the server, handling object transfer, validation, authentication and basic CRUD (Create, Retrieve, Update, Delete) operations and asynchronous calls almost transparently.

Data transfer between the client and the server has always been tricky. There is a lot of plumbing code to write: encoding, remote calls, error handling, asynchronous issues, validation (you have to validate stuff on the server for security and on the client for instant feedback and user experience). Let’s see how .NET RIA Services handles some of these!

Let’s have a single table from our old friend, the Northwind database in a LINQ to SQL dbml file:

image

(Yeah, that’s me :) – btw, sorry for the quality of the code snippets below, they are just frames from the same presentation video)

Using the Visual Studio .NET RIA Services wizards (for details, please check the tutorial on the same download page – this blog post is by no means a step by step introduction), let’s create a NorthWindService.cs class. This is still on the server side:

image

You can see that the NorthWindService class is inherited from LinqToSqlDomainService. .NET RIA Services can also connect to Entity Framework or even POCO object stores if you wish.It has functions like “GetCategories”, “InsertCategory”, etc, all generated automatically:

image

Also note the EnableClientAccess attribute – that means that members of the NorthWindService class are (more or less) exposed to the client. This means, that after building, the code generator of the .NET RIA Services runs, and we get a lot of code generated on the Silverlight side that allow for using the same classes (Category in this case), with the same properties, and the CRUD functionality on the client side. Even validation logic and other custom code can be copied to the client! As we use the same .Net Framework on both the client and the Server, this source code reuse is possible and trivial.

To actually show and download the data from the server, this is all I have to do on the Silverlight side:

image

myDG is just a simple DataGrid, with absolutely no customization, only its name is provided in XAML.

If we run the application now, this is what we see:

image

This is an empty Datagrid, but if you watch closely, you can see that the fields of the Category class are already displayed as columns. So, at this moment, the Datagrid has an ItemsSource – a list of Category objects, but with zero items. If we wait for another second, the list populates:

image

What happened here? Well, the server needed a little time to compile everything and get the categories from the database. When it finished, it returned the resulting Category objects to the Silverlight client, which displayed it automatically. A lot of magic is happening behind the scenes: the RIA Services callback happened asynchronously, it filled the collection that was bound to the Datagrid’s Itemssource, and finally the Datagrid displayed the categories. All without any specific code after the load operation started!

What happened on the SQL Server in the meantime? Let’s fire up an SQL Server Profiler, and see!

image

This is a perfectly normal SQL Query that you or I would write – maybe a bit more [] and t0 though. :) So, the client side “nwc.GetCategoriesQuery” travelled to the server, and this is the SQL Query that was run on the SQL Server. Let’s make the query a bit more complicated!

image

You see that through the power of Intellisense, LINQ and .NET RIA Services, we can write a strongly typed query against the Northwind database within the client application!

image

So, we only want to get the categories that have “C” as their first character.

And here is the result with the single such category displayed:

image

Yeah, sure, no problem – it must have downloaded all the categories, and filtered on the client side, right? Wrong! Let’s see the SQL Profiler what happened on the server!

image

Nope – although the query is now executed via sp_executesql, we have a nice Where clause here even the StartsWith has been properly translated to LIKE. Pretty powerful, isn’t it?

Remember, this is just the scratching of the surface of 0.1% of the .NET RIA Services Framework. But hopefully, it is enough to get you interested. For more information, read the downloadable intro material, check out posts from Nikhil or Brad Abrams’ series on a Business Apps Example.


Posted Sep 08 2009, 04:58 PM by vbandi

Comments

Discovering Silverlight 3 ??? 5 minutes of RIA Services - VBandi's blog - Dotneteers.net wrote Discovering Silverlight 3 ??? 5 minutes of RIA Services - VBandi's blog - Dotneteers.net
on Tue, Sep 8 2009 21:10

Pingback from  Discovering Silverlight 3 ??? 5 minutes of RIA Services - VBandi's blog - Dotneteers.net

Twitter Trackbacks for Discovering Silverlight 3 ??? 5 minutes of RIA Services - VBandi's blog - Dotneteers.net [dotneteers.net] on Topsy.com wrote Twitter Trackbacks for Discovering Silverlight 3 ??? 5 minutes of RIA Services - VBandi's blog - Dotneteers.net [dotneteers.net] on Topsy.com
on Wed, Sep 9 2009 13:35

Pingback from  Twitter Trackbacks for                 Discovering Silverlight 3 ??? 5 minutes of RIA Services - VBandi's blog - Dotneteers.net         [dotneteers.net]        on Topsy.com

Dew Drop – September 9, 2009 | Alvin Ashcraft's Morning Dew wrote Dew Drop – September 9, 2009 | Alvin Ashcraft's Morning Dew
on Wed, Sep 9 2009 14:30

Pingback from  Dew Drop – September 9, 2009 | Alvin Ashcraft's Morning Dew

DotNetShoutout wrote Discovering Silverlight 3 – 5 minutes of RIA Services - András Velvárt - Dotneteers.net
on Wed, Sep 9 2009 18:49

Thank you for submitting this cool story - Trackback from DotNetShoutout

Sanjeev Agarwal wrote Daily tech links for .net and related technologies - September 9-12, 2009
on Thu, Sep 10 2009 11:51

HTML clipboard Daily tech links for .net and related technologies - September 9-12, 2009 Web Development

mian wrote re: Discovering Silverlight 3 – 5 minutes of RIA Services
on Wed, Mar 24 2010 13:27

How can we pass where clause as string to update method of DomainService and how to handle it in domainService ,,

such that I have an Entity Customer and where condition as

string weh="Name=''ghous"

now objDomainService.Update(customer, weh);

How to handle this on In Domain Service Class as in ur examle

Add a Comment

(required)  
(optional)
(required)  
Remember Me?