.NET RIA Services MIX '09 Talk - Slides + Code

Slides and code for my MIX '09 Talk - Building Data-driven Applications with Silverlight and ASP.NET

.NET RIA Services (formerly code-named Alexandria and what I have been working on for the most part during the past year) is now public. It has even been termed as the real premiere of Silverlight, which is nice to read as you might imagine :-). I had a similar blog post yesterday about the progression of Silverlight from its early v1 roots to a real app platform in v3.

A quick description of .NET RIA Services is in order:
.NET RIA Services builds on Silverlight 3 on the client and ASP.NET on the server to simplify building n-Tier data-driven applications. First, .NET RIA Services provides a prescriptive CRUD-based pattern for authoring your application/domain/business logic, i.e. queries, operations, rules for authorization, validation etc. on the middle tier and makes that functionality easily consumable from your presentation tier in the form of bindable data. Second, on the presentation tier, we're providing new data controls such as a DataSource, enhanced DataGrid and DataForm/DataPager controls for mainline data/LOB scenarios. Third, we're also providing higher level building blocks such as authentication, cross-tier user state and the like.

I have some more insight to share (that deserves its own blog post) around what .NET RIA Services really is, but I wanted to do a quick post related to my MIX talk, T41F - Building Data-Driven Applications in ASP.NET and Silverlight (click for the video). Here are the accompanying slides and code:

I know some folks were eager to go over what I showed line by line. Feel free to ask questions you might have in the comments section below.
Update 3/24:Added missing SQL script I forgot to include, that you need to recreate the database to run the samples on your end!

A quick overview of what I showed:

  • Hello Data/Hello .NET RIA Services - I showed a simple demo to write some simple application logic on the server to expose a list of products and render them declaratively in a DataGrid/DataForm via a DomainDataSource control within Silverlight. I extended this demo to show a facility we have for doing simple projections when sending data down to the client.
  • Store Application - this was a simple application based on the IBuySpy sample data, containing products and categories. I showed accessing data imperatively using LINQ queries on the client that are sent down to the server by .NET RIA Services. I next showed editing, ala Update bit of CRUD, and then showed one cool new addition we're adding to the CRUD foundation - custom application logic methods (to cater to specialized and domain-specific update operations). Along with editing I showed imperative validation on the server (with the error flowing to the client), validation rules attached declaratively using metadata annotations, and custom validation through a simple method in code that can be shared between the client and the server. Finally I showed batching of changes where the client can queue up a number of changes to send as a batch to the server.
  • Printing for Silverlight - While this is a cool and often requested scenario in itself, I used this scenario as a way to show how you can reuse your application logic you wrote for your Silverlight client app to also do server-side rendering to produce HTML, using the familiar ASP.NET DataSource control model.
  • Ajax client - Once again an example to show reuse of the application logic from an Ajax client. Specifically this shows how the infrastructure we're building between the client and server is based on open, standard and RESTful principles and approaches, so it is consumable from a non-.NET client, such as a jQuery-based Ajax app.
  • Azure backend - This demo showed the pattern of writing application logic scale to beyond local relational databases and work in the same manner for something like cloud-based storage. For this I had a sample scenario demonstrating a bookshelf, and the books stored on Azure. The client application used an Accordion control, which is new in the Silverlight control toolkit to simulate a bookshelf. This demo is based on prototype code to access the Azure storage. You'll also need an actual azure token and need to update the web.config with your information in the connectionStrings section to run the demo on your machine.
  • Offline - this was probably the most exciting demo. It showed how you can implement an app that can now run outside the browser, thanks to the new Silverlight 3 feature, but use the .NE T RIA Services pattern to bring data down to the client, store it along with pending changes to local storage, and periodically, as and when the app has network connectivity, submit pending changes, and update the local cache of data. I should note that this demo is also based on early prototype code.

Two demos I didn't show due to time constraints, but included in the demo bits:

  • Testability - I have a test project to test my application independent of my presentation tier by directly accessing the application logic and unit testing by mocking out the underlying data access layer. So specifically in my Azure app, I can test the app without relying on Azure at unit test time.
  • Plain Old CLR Types - Our entire model isn't reliant on actual databased-backed data. This demo demonstrated writing some application logic on top of the list of running processes and publishing them to the client to report the longest running applications.

Posted on Thursday, 3/19/2009 @ 6:05 PM | #Silverlight


Comments

47 comments have been posted.

Ben Hayat

Posted on 3/20/2009 @ 7:51 AM
Hi Nikhil;

That was the best session I had seen. Great job.
I really want to learn more about using Azure, SL and .Net Ria services. I hope you'll provide a more detail blog or article on this.

Thanks once again!
..Ben

Nikhil Kothari

Posted on 3/20/2009 @ 9:47 PM
@Ben - thanks!
I definitely want to blog about these three technologies. I think the combination of Azure, SL and .NET RIA Services is a super combination.

Sanjay Singh

Posted on 3/20/2009 @ 11:04 PM
Hi Nikhil
Great to know that finally SL has taken a serious steps in the LOB world - otherwise it was just compared to Flash/Flex as audio/video & show-off things. Thanks for the excellent session. It will be great to learn 3 big things from MS - SL, ASP.NET MVC, & Azure. I hope you can provide more insight into these technologies on your blog. Have a great day. -Sanjay

Steve Gentile

Posted on 3/21/2009 @ 7:08 AM
Side note: does your code include the jquery sample ?

Nikhil Kothari

Posted on 3/21/2009 @ 9:42 PM
@Steve
Yes, the jQuery sample is included - see ProductList.htm in the web application.

Steve Gentile

Posted on 3/22/2009 @ 8:50 PM
Ahhh JTemplate - I was thinking while watching your video 'that isn't inherit jQuery functionality is it?' :)

I didn't dig down into the service call, I assume that data was serialized to json for that json ajax jquery call to succeed?

Nikhil Kothari

Posted on 3/22/2009 @ 11:33 PM
@Steve
Yes, strictly speaking jTemplate isn't part of jQuery. It is however a super minimal templating engine with no dependencies...

Yes, the data is serialized as JSON for this scenario to work. We actually use JSON even between Silverlight and the server, since its a nice, compact and minimal syntax representation.

Steve Gentile

Posted on 3/23/2009 @ 6:09 AM
"We actually use JSON even between Silverlight and the server, since its a nice, compact and minimal syntax representation. "

ok, great, yes, that should really cut down on the size of the payload.

Noam Arbel

Posted on 3/23/2009 @ 8:14 AM
Great stuff. Very exciting, and perfect timing for me.

Can you please share the DB files as well, so I can walk through the code with some data. Thanks.

Nikhil Kothari

Posted on 3/23/2009 @ 8:59 AM
@Noam
I believe I included a sql script that should allow you to recreate the db on your end, so the download isn't huge - just create a SQL db called "Store" and run the script.

Steve Gentile

Posted on 3/23/2009 @ 3:39 PM
I think it would be interesting to see how RIA.NET integrates in with ASP.NET MVC - as the 'model'. In my recent asp.net mvc application, a business layer like RIA.NET (I'm using NHibernate) to be my DTO layer would have been very nice with all it's validation capability, etc...

Obviously with the ajax example, and the requirement for SL3 with RIA.NET I'm seeing that it doesn't need to thought of as a part of Silverlight whatsoever correct?

Michael Mitiaguin

Posted on 3/23/2009 @ 9:09 PM
You didn't seem to include sql script or mdf in mix09.zip . If not included, where else script /mdf may be downloaded.

Noam Arbel

Posted on 3/24/2009 @ 12:14 AM
Nikhil, Thanks for the replay. I may be missing something, but I cannot find the SQL scripts. Where are they located.

Thanks.

Nikhil Kothari

Posted on 3/24/2009 @ 6:46 AM
@Noam - oops, I realize I had forgotten to include it. Thanks for bringing it up. I've put up an updated zip - this time via Live Skydrive, since FTP uploads on my site just seem to have broken...

Nikhil Kothari

Posted on 3/24/2009 @ 6:48 AM
@Steve
Indeed this domain service pattern isn't restricted to just Silverlight and Ajax. We have prototypes of some MVC integration going on over here, and will share that through the MVC releases. Specifically the work going on is to simplify using a domain service imperatively from your own code rather than through a service layer since you're already on the server.

Rob Beasley

Posted on 3/24/2009 @ 6:56 AM
Hi Nikhil,

Nice presentation.

I downloaded your code sample. I built the Azure sample (without making any changes) and got the following error.

"Error 3 Type 'Bookshelf' is not a valid domain service. Domain services need to derive from DomainService, be non-generic, be marked with an EnableClientAccessAttribute, have a parameterless constructor and cannot be abstract. MyAppClient."

Any thoughts on why this error occurred?

David Jacobson

Posted on 3/24/2009 @ 1:45 PM
Thanks for the data. I have just started playing with the sample. But it is pretty impressive to install the offline sample out of the visual studio server and then launch it from my start menu. It looks pretty good too.

Eoin

Posted on 3/25/2009 @ 5:14 AM
Hi Nikhil,

Great presentation.

I've a few questions though.
I'm creating my own application using the same layout and controls you're using (Buttons on the left, DataGrid on the right).
It works fine, when I click the button, it loads the data in the DataGrid as per the Button clicked.

I've discovered in your application you have an attribute in the metadata on the VendorName - [Include("VendorName", "VendorName")] and when I use this for my own fields that information comes across, but obviously only for that field.

Is there a way to send the whole object back as in the whole Vendor object in your application, and not just on field.

Or is this the way it's done ??

Is it always done this way ? - can we not get access the data using {Binding Vendor.VendorName} - Is this possible ??

Hope this makes sense :-)

Thanks,

Eoin

Nikhil Kothari

Posted on 3/25/2009 @ 2:43 PM
@Eoin
If you put a simple [Include] on the Vendor property, it will include all of the Vendor object. I was specifically using the extended usage that allows me to include specific members.

Rob Beasley

Posted on 3/29/2009 @ 6:09 PM
Ah... I think I understand why you did not respond, microsoft either haven't officially built the RIA for Azure table storage or for commercial reasons their not ready to release.

A more specific question then, will there be a Domain Service for Azure Table Storage and when will it be released.

s

Posted on 3/30/2009 @ 4:33 AM
Nikhil, this is great! Thank you very much! One of the best demos!
A couple questions!
First code base was missing sql script, but when I ran offline solution I was able to create desktop icon.
I downloaded the next version for sql script(thanks for adding it) and had deleted the desktop icon, but now I don't see a button to go offfline. Am I misisng something?
I also saw an excpetion getting thrown while saving multiple changes, which I will try to repro. Also, where is the validation? I tried to add text in currency fields, I did not get validation message...maybe it was not added. I will look into it further. Will be a good starting point to learn.

Hariraj Singh

Posted on 3/31/2009 @ 2:22 PM
Hi,
I just have a small question on taking Offline data. Do we have any out of the box security on the offline data that is been stored in the machine like encryption, password protection and what about vista's UAC

Thanks.

zoranj

Posted on 4/1/2009 @ 6:37 AM
Nikhil,
This is really amazing.
I am playing these days with RIA Services CTP and I have problem with EntityFramework based DomainService associations. I have simple Master-Details relationship Category to Product.
I created on the client side new Category and without previous submitting changes I created associated Product for this Category.
Seems to me that even if I added [Include] attributes client is still not sending EntityRef data (associated entitty) to the server and of course because of that Insert operation for Product fails.
Is that feature just still not available in CTP or I am doing something wrong? I was using autogenerated EntityFramework model (I didn't do any manual adjustments to the model).
Thanks

Nikhil Kothari

Posted on 4/1/2009 @ 7:55 AM
@Rob - I think there is a bug in the sample and in our code-gen. There needs to be a placeholder parameterless ctor for code-gen to succeed right now. We are certainly looking at support for Azure - we have to figure out the right option - is it a sample, is it part of Azure or should it be part of domain services.

@s - the latest download should have the sql script.

@Hariraj - no encryption is built in. Also, keep in mind the offline sample was a proof of concept to illustrate the possibilities that the pattern yields. We need to certainly do a lot more to turn this into an actual out-of-the-box capability.

Nikhil Kothari

Posted on 4/1/2009 @ 7:57 AM
@Zoranj - I'd recommend trimming down to a suitable repro and posting it/asking for help on the forums. The scenario should definitely work... its a pretty common thng. Are you using LinqToEntitiesDomainService?

Zoranj

Posted on 4/1/2009 @ 12:52 PM
Only purpose of my question was to clarify is that maybe known issue in CTP version. Thank you for the clarification – that is really only thing I needed.
Yes, I was using LinqToEntitiesDomainService. I just did exercise of replacing it with “LinqToSqlDomainService” and all works just fine. In both cases I was using auto generated models (edmx/dbml) from the same DB wihout making any manual changes to them. All other code is the same (or at least I think it is the same :) ).
Thanks.

Rob Beasley

Posted on 4/5/2009 @ 4:45 AM
Thanks Nikhil,

For mine, part of domain services.

Regards

Rob

sam

Posted on 4/7/2009 @ 1:29 PM
Nikhil,

I am unable to download source. When I click the download link, it displayed a blank page without anything.

NerishaB

Posted on 4/9/2009 @ 5:22 AM
Hi there

I am trying to reproduce the examples created in the Mix09 Code and Slides provided but get an error whenever I run any of the examples. I have VS2008, Silverlight 3 SDK and the RIAServices installed. Do I need SQL 2008 or SQL 2008 Express installed as well?

Thanks

Nikhil Kothari

Posted on 4/9/2009 @ 7:57 AM
@NerishaB - yes, you need SQL and you need to create a db called Store, and run Store.sql to initialize the db before the samples will work.

Ben

Posted on 4/17/2009 @ 6:32 PM
@Rob - try and add a parameterless constructor, it worked for me. There was a hint in the error message.

s

Posted on 4/19/2009 @ 6:39 AM
Will there be a Silverlight FX for SL 3?

lilsteps

Posted on 4/19/2009 @ 2:48 PM
how can I add validation to unitcost for valid decimal numbers. I mean with the converter in place, it is throwing an exception in convertback when I o not enter a value or enter text.

Nikhil Kothari

Posted on 4/20/2009 @ 3:20 AM
@s - yes, there will be a Silverlight.FX for SL3.

@lilsteps - I think the converter for currency was just a string format one - you'd have to implement ConvertBack to parse out the decimal part by separating out the currency symbol... a few lines of code that weren't in the sample...

MakerOfThings

Posted on 4/20/2009 @ 2:46 PM
Nikhil, Thanks for the Mix Video, I have a much better understanding now. I'm now left with a few questions...
--- With all the openness of RIA Services, does that mean the Framework could (in theory) support iPhone or Blackberry as well?
--- Is there any guidance for selecting offline sync technologies : RIA Services, Astoria Offline, Sync Framework?
--- How does RIA relate to WCF? Does it enhance, replace, or is parallel to WCF? How about Astoria? Can I call stored procs (Azure Mindset), or methods (WCF mindset) with RIA?

Thanks!

Woshiernog

Posted on 4/23/2009 @ 10:51 AM
Nikhil,

I'm new to this whole RIA Services thing and I was wondering how I would block the Silverlight application thread to wait until I have loaded information from the database tables?

Nikhil Kothari

Posted on 4/23/2009 @ 8:59 PM
@MakerOfThings
Generally you can have a client on any presentation tier talk to the server. The thing you want to think about is how the client versions lock step with the server, since the contract of your services very much depend on the specific code you write in your domain services, and on your entities.
I think sync is a problem where you have to apply technology as well as a app specific requirements, constraints and scenarios before deciding what is right...
RIA Services build on top of WCF. WCF offers a general solution, and RIA Services offers a more prescriptive solution geared toward a smaller spectrum of scenarios.

@Woshiernog
I don't think you want to think of the problem as "how would I block". What you want to think of are how to let the user meaningfully interact with the app, possibly in a reduced manner while a request has been made and you're waiting for a response. Alternatively, what is the way to show progress and activity, rather than block.

Luiz Goncalves

Posted on 4/25/2009 @ 9:40 AM
Nikhil, First of all, nice presentation.

I'm trying to get the "MIX09 Slides and Code.zip" file but the link not seems to be working. How can I get this examples?

Thanks

Imran Shafiq

Posted on 4/26/2009 @ 3:41 AM
Nikhil:

.Net RIA services look very promising but since I have been reading up on all the new stuff from Microsoft (ASP.Net MVC, Silverlight 3, .Net RIA services, Entity Framework, ADO.Net Data Services, Azure, Sync, Velocity etc), its getting a little confusing on how to correctly place these pieces together. And even though I know there is no concept of ONE solution to all problems, still I would like your comments on this.

The way we have been doing our LOB web applications is:

1. IE (HTML/CSS/Javascript) on client tier
2. MS AJAX.Net, ASP.Net on presentation tier (Web Client Software Factory) and p&p Caching Application block
3. pure WCF services on business tier (Web Service Software Factory) with business logic layer and data access layer based on NHibernate and NCache for distributed caching
4. SQL server as data tier

In case of LOB desktop applications we replaced 1 & 2 with Smart Client Software Factory (WinForms) with p&p Caching Application block

From what I have been reading, both .Net RIA services and ADO.Net services are built on top of WCF and both out of the box utilize Entity Framework.

So keeping that in perspective, will this be a correct understanding:

a. For RIA applications, use SilverLight on client tier AND in case of pure desktop applications, use WPF (Composite WPF) on client tier
b1. For Silverlight clients, use .Net RIA services on business tier with business logic layer and data access layer based on Entity Framework with Velocity for distributed caching
b2. For WPF clients, use pure WCF services on business tier with business logic layer and data access layer based on Entity Framework with Velocity for distributed caching (since .Net RIA does not support WPF clients yet)
c. SQL server as data tier

Where do the ADO.Net Data services fit in? Will Sync be useful only with offline/disconnected WPF clients, does it have any place with Silverlight clients? When .Net RIA services start working with WPF clients, will we need pure WCF Services in the above picture?

Nikhil Kothari

Posted on 4/27/2009 @ 12:56 PM
@Imran
Yes, certainly there is a lot of tech, and I feel it too! I think you want to think of where each technology fits in into the overall app arch, eg. some things are about presentation (MVC, SL), some are about data access layer (EF, ADO.NET DS, Azure), and some are about optional capabilities (Sync, Velocity). Many are choices within a category, that you need to pick from depending on your app's needs. In that sense, .NET RIA Services is like glue that helps you focus on the app logic that stitches these things together once you've made your choices along with the plumbing between tiers in a multi-tier solution.

Both .NET RIA Services and ADO.NET Data Services build on WCF, but aren't hard-bound to EF. In fact, .NET RIA Services starts from the premise that your data is simply objects, and EF is one of multiple ways to materialize those objects. In fact, my demos showed Azure, Linq To Sql and even plain old CLR objects populated from System.Diagnostics APIs.

You will be able to use .NET RIA Services for web-deployed WPF apps as well. Our current bits focus on Silverlight, but from an engineering perspective we're building for WPF as well, and will cater to that scenario as well over time.

We're looking at how .NET RIA Services leverage ADO.NET Data Services from an infrastructure perspective, as well as from a consumption perspective.

Sync starts to become interesting with offline execution models, and that starts to become interesting as you go outside the browser. So in some sense sync is interesting with Silverlight as well, as it has a story that goes beyond a browser.

WCF services are a great way to organize your functionality you want to expose across disparate systems and across multiple applications, where you want to author, manage, evolve a contract, as well as evolve the systems/apps at their own pace.

Hope that helps!

Imran Shafiq

Posted on 4/27/2009 @ 2:13 PM
Thank you for the explainantion. I did not really understand in a few of the sessions/blogposts when it was mentioned that .Net RIA does not support WPF yet, I assumed we should be able to use the generated DomainContext on the client side in a WPF App or XBAP as well?
I think the missing piece for WPF is the "gluing" flag in the silver light project properties.

1. In the current release of .Net RIA, is there a way to do that gluing manually somehow to attach a WPF App with the serverside ASP.Net project? I was planning to do a prototype with WPF & .Net RIA if possible.

2. In the current release can we utilize multiple DomainContexts in the SilverLight client? i.e. author Multiple DomainServices on the ASP.net server side.

Imran.

clems

Posted on 5/27/2009 @ 1:33 AM
Hey Nikhil.
Congratulations on your efforts, this stuff is very exciting.

I could not build the azure project of your demo though.

Error 1 Code cannot be generated for the DomainService 'Bookshelf' because it doesn't have EnableClientAccessAttribute or a default constructor. MyAppClient

If I add a default constructor then there is another error.
Error 1 The TypeDescriptionProvider 'Microsoft.Azure.DomainServices.AzureTypeDescriptionProvider' specified does not provide a public constructor of one of the supported signatures. MyAppClient

Bartosi

Posted on 7/28/2009 @ 4:33 PM
Hi Nikhil!
Thanks for the presentation, but could you update the code (of the store) to the actual ria?.
Tanks, bts.

Bartosi

Posted on 7/28/2009 @ 4:35 PM
Hi Nikhil!
Thanks for the presentation, but could you update the code (of the store) to the actual ria?.
Tanks, bts.

Rachida Dukes

Posted on 8/2/2009 @ 8:58 AM
Hi Nikhil!
I really like your presentation. Is it possible to update the "Store Code" to the latest version of silverlight 3.0 and July preview RIA SErvices?
Thanks for the good work
Rachida

Hoang

Posted on 12/16/2009 @ 8:24 PM
Hi Nikhil;

Great job. I really like your presentation. I do the first demo(Hello Data/Hello .NET RIA Services) of your presentation. It's working great on Business Silverlight App and Silverlight App hosted on an ASP.NET Web Project. But when I hosted it in a ASP.NET MVC it didn't work. I cannot get my data from my server. I don't know what wrong with it! Can you help me solve this problem!

Kapil

Posted on 2/26/2010 @ 5:36 AM
Hi Nikhil,

I really linked the approach for synchronizing data across client and server. If possible please update it to latest version.
Post your comment and continue the discussion.