RIA Services mainly targets Business Application Development, and comes across good for this purpose from a few different angles.

RIA Services simplifies the traditional n-tier application pattern by bringing together the ASP.NET and Silverlight platforms. If you have ever gone through the motions of creating a WCF Service, and then adding a service reference to your Silverlight project you will quickly find that the service calls are all asynchronous, and require you to specify an OnRequestCompleated method for calls that you make to that web service. While there are asynchronous programming patterns out there most business application developers prefer the tried and true N-Tier approach. Asynchronous Method calls make N-Tier Architecture difficult

As stated above Ria simplifies tiered architecture this means it is a great choice for creating applications using some of the more popular architectural patterns like MVVM, and MVC.

Because RIA Services is from Microsoft, you get tight Visual Studio Integration, and lots of Blogs, and Documentation covering it's use. While some of the open source projects out there are pretty good, most lake adequate documentation and have a steep learning curve.

Ria Services is flat out great for Rapid Application Development. There is Code Generation generation built into Visual Studio to generate Domain Services directly from ADO.NET Entities Models that your Silverlight applications can consume.

Where Can I Get WCF RIA Services

You can Get Wcf Ria Services From the Microsoft Web Platform Installer, located here.

Highlight the Web Platform Tab

Scroll Down to Tools

Click the customize Tab

and check off what you need

If you don't have Visual Studio go ahead and check off to get the Express Version. You obviously want to get the RIA Services Toolkit, and while you're here get the the Silverlight 4 Toolkit, and Tools for Visual Studio as well. After the install completes you will have everything you need to work with Silverlight 4 and RIA Services from within Visual Studio.

Options for Integrating WCF RIA Services into your Projects

There are a few different way out of the box to integrate WCF RIA Services into your projects using Visual Studio

Using the Silverlight Business Application Project Template

RIA Services in the Silverlight Application Project Template

Using the RIA Services Class Library Project Template

In this post we take a look at each of these approaches, talk about when and how they are useful, and show how implement each one. For this purpose I have created a Visual Studio Solution containing each implementation listed aboveIn the real world you are not likely to have a solution which implements any combination of these approaches, but for this example it is nice to have them all in one place to look at.

The Silverlight Business Application Project

If you are creating an application that requires Login, Registration, and User Authentication the Silverlight Business Application Project Template is a good way to go. It includes all this right out of the box. It also has website like layout and styles you can customize and some useful helper methods. You can actually learn a few things just by creating this project and then giving it a gook look over.

To create a Silverlight Business Application:

Right Click on your Solution and select "Add New Project", Select "Silverlight" from the Tree Menu on the Left, and then Select "Silverlight Business Application".This will create a new two Projects in you solution automaticallyYou now have a Web Application Project to host your Silverlight Application and Domain Services, and The RIA Link between the two projects is all set up so you can begin adding and consuming WCF RIA Services. If you run the project now you will see all the out of the box features I mentioned are there.

Configurable Layout and Styles

Login

Registration

Not bad for right out of the box. I do have a couple of small issues with this though. Sure, it's great Microsoft has given us all this stuff without having to write a single line of code, but, I would have a couple things different if it were up to me.

1. I wish the project template had a few config options upon creation. For example, for larger projects I may want all my services to be in a WCF RIA Services Class Library (RIA Class Library covered in detail below) in instead of in the Web Application Project. Now I would have to move them.

2. I'm not really sure what kind of Architectural Pattern they are trying to implement here. As you can see from the image of the Solution Explorer above there is a folder named "Models" in both the Web Application Project, and in the silverlight project. Then there is a Views folder in the Silverlight project that has views in it, but then no ViewModels or Controllers. Okay, so my point is what are they going for here? It makes me want to start moving the code around. If I'm not alone on this please leave me a comment. Anyway, small issues compared to the big picture.

WCF RIA Services Enabled Silverlight Application

If you don't need all the stuff that's included in the Silverlight Business Application above, or plan to just write them yourself, you can also enable RIA Services in a regular silverlight application.

To create a WCF RIA Services Enabled Silverlight Application:

Right Click on your Solution and select "Add New Project", Select "Silverlight" from the Tree Menu on the Left, and then Select "Silverlight Application".When you click OK to add the new Silverlight Application a Dialog will appearer allowing you create a New Web Application to host your Silverlight Application in, or to host your Silverlight Application in an existing Web Project. Either way all you need to do is check the box to "Enable WCF RIA Services".Then when your Project is created, it will already be set up to use RIA Services. You can now start adding domain services to your web project and the RIA link is in place and ready to go.

WCF RIA Services Class Library

The last option is the WCF RIA Services Class Library. In my experience the more separation you have in your solution the better. This project template allows you to house your Domain Services in separate assemblies.

To create a Solution that uses a WCF RIA Services Class Library:

Right Click on your Solution and select "Add New Project", Select "Silverlight" from the Tree Menu on the Left, and then Select "Silverlight Application".When the project Dialog box appears allowing you to host your silverlight application in an existing or new Web Application, leave the "Enable WCF RIA Services" checkbox UN-CHECKED. The RIA Link will exist in the RIA Services Class Library.

Now right Click on your Solution and select "Add New Project", Select "Silverlight" from the Tree Menu on the Left, and then Select "WCF RIA Services Class Library".This will actually create two projects. The RIA Services Class Library Consists of a Windows Class Library and a Silverlight Class Library and the two projects created contain the RIA Link. The project ending in .Web is the Windows Class Library and will run on the server while the other is the Silverlight Class Library will run on the client. Your solution should now look something like this.All you need to do now is:

Add a reference to the Silverlight Class Library in your Silverlight Application

Add a reference to the Windows Class Library in your Web Application

And you are now set up and ready to start adding Domain Services to your server project for consumption in your Web Project. When using this set up you should add your domain services to you Windows Class Library section of your RIA Services Class Library.

Creating and Consuming Domain Services

Now that we know how to set up our RIA Services Project, Lets take a look at adding a Domain Service and consuming it in out Silverlight client to test that we have everything wired up correctly. In all of the scenarios listed above you will always add your Domain Service on the server side and consume that service on the Silverlight Client.To show you how quick and easy it is to get a Domain Service up and running we are going to create a Domain Service form and ADO.NET Entities Data Model.

Start by Creating a Database. Mine consist of only one table with a very simple schema for this example.

Now right Click on your Web Project and select "Add New Item", Select "Data" from the Tree Menu on the Left, and then Select "ADO.NET Entity Data Model".

Highlight "Generate From Database" and click "Next".

Select your Target Database and click "Next".

Select the tables you want to generate the Model from and click "Finish".

Now that your Entities Data Model has been created do a Rebuild on the project before you do any thing else. This is important because if you forget to rebuild what will happen is when you go to create the Domain Service it will not be able to find your Entities. So go ahead and rebuild now and then we can create out first Domain Service.

Now right Click on your Web Project and select "Add New Item", Select "Web" from the Tree Menu on the Left, and then Select "Domain Service Class".

Click "Add" and you will get a Dialog Box Allowing you to generate your Domain Service from your entities. Select Enable Editing if you want it to Generate Update, Insert and Delete methods as well.

Now Click "OK" and it will generate your Domain Service class. It will look something like this.

// TODO: // Consider constraining the results of your query method. If you need additional input you can // add parameters to this method or create additional query methods with different names. // To support paging you will need to add ordering to the 'Contacts' query. public IQueryable GetContacts() { return this.ObjectContext.Contacts; }

Notice it created services methods to preform all the CRUD opperations we need against our Database.Now in our Silverlight project we will create a Grid in our MainPage.xaml to display our data like so:

About ASPHostPortal.com

We’re a company that works differently to most. Value is what we output and help our customers achieve, not how much money we put in the bank. It’s not because we are altruistic. It’s based on an even simpler principle. "Do good things, and good things will come to you".

Success for us is something that is continually experienced, not something that is reached. For us it is all about the experience – more than the journey. Life is a continual experience. We see the Internet as being an incredible amplifier to the experience of life for all of us. It can help humanity come together to explode in knowledge exploration and discussion. It is continual enlightenment of new ideas, experiences, and passions