If you have used WCF RIA Services along with Entity Framework for Silverlight applications, you know how useful they are for performing database operations from your application.  With the WCF RIA Services Toolkit, it gives you even more flexibility to expose your RIA DomainService methods to not only a Silverlight application, but any application that can access a SOAP or JSON endpoint.
I will provide some steps here for setting up and consuming data through a SOAP endpoint.

1. Install WCF RIA Services Toolkit

You will need to install the toolkit in your development environment.  You can get it here...

It is quite easy to enable Out-of-Browser (OOB) mode when building a Silverlight application.  Open up the project properties on the Silverlight project and check the box to "Enable running application out of the browser."

The more difficult task is troubleshooting problems when the application works in browser, but not out of browser.  First, to debug OOB applications in Visual Studio, you need to open the Silverlight project properties and in the "Debug" tab, set the start action to "Out-of-browser application" and select the appropriate project from the dropdown list.  Next, set your Silverlight project as the startup project.  Now ...

When creating a domain service on an Entity Framework model typically there is an option to generate the associated metadata classes for adding attributes to the public properties .

It is necessary to have these metadata classes when:

  • Validation attributes such as RangeAttribute, RequiredAttribute
  • Using the IncludeAttribute to send child entities to the client
  • ExcludeAttribute to not send a property to the client
  • Others such as DisplayAttribute, RoundtripOriginalAttribute

One thing to note is that this class is not necessary to use a Domain Service. If you have any of the conditions above that you need to do then the metadata ...

Using stored procedures is already built into the Entity Framework but using stored procedures with WCF RIA Services then ultimately Silverlight requires some manual work. In this example I am going to step through adding an entity to an ADO.NET Entity Data Model all the way through calling the stored procedure from Silverlight.

 

First setup a Silverlight project of your liking with and make sure to enable WCF RIA Services.

 

Create a new ADO.NET Entity Data Model in the Web project. Connect this data model to the AdventureWorks2008 sample database. At the Choose Your Database Objects page select the Address table ...

 RIA Services provides a Authentication Domain Service template to use for enabling windows or forms authentication in your Silverlight application.  Most of the out-of-the-box setup works fine if your project has everything in a single assembly, but when building larger scale applications that may use a RIA Services Class Library, there are a few extra steps you'll need to take for everything to work correctly.

You'll know there is a problem finding your AuthenticationContext if you get this error:

The DomainContextType is null or invalid and there are no contexts generated from AuthenticationBase<T> 

If you are setting up your WebContext ...

 

Recently I was given a task of creating a quick example of someone making a data change to a database table then someone else being able to see the new data. Seemed simple enough. I created a WCF RIA Services application with a simple grid and submit/refresh buttons  on it. I brought up two instances of the application and had one instance change the data and the other refresh it. To my amazement the second instance didn’t see the new data.

I brought up SQL Server Profiler to see what was going on. When hitting the refresh button I ...

  I have written quite a few WCF RIA Services applications now and almost every time I need to pre-fetch some data before showing a Silverlight page or dialog. For instance you might need to get all the years and employees available to so you can put them in ComboBoxes for a dialog. You wouldn’t necessarily want to do this in the Loaded event of the dialog because the dialog will come up with empty information then fill in when the query has returned.

Another problem is that the code turns ugly and hard to manage if you have multiple ...

There have been a few instances when I would like to have an identical copy of an object but want them to be different instances. There are a few brute force ways to do this by either copying the values one by one or by using reflection to iterate over variables, properties, etc. The problem is that these methods are not very generic and need to be tweaked for each situation.

I have discovered that there are a few ways to clone an object by serializing then de-serializing an object into a new deep-copy instance of that object.

Method 1 ...

Visual Studio 2010 provides a great starting point for developing Silverlight Line of Business applications with WCF RIA Services.  Here at Falafel Software, we find ourselves using this template quite often, so we decided to make some enhancements to the base template to give ourselves a head start every time we begin a new project.  Jump to the bottom of this post to get the solution template for yourself.

 

Here are some improvements we’ve made:

1.  Four projects are better than two

The standard two-project setup is great for simple solutions, but when you are building enterprise-level applications, it ...