When this blog first started I named it "The Elephant and the Silverlight" which was referring to the old story, "The Blind Men and the Elephant", which was translated by John Godfrey Saxe. If you are not familiar with the story it is on the very first post of this blog. In the story multiple blind men examine an elephant by touch and each comes away with a different understanding of what an elephant is.
The story of WCF RIA Services is much like the story of the elephant. As I discussed in Musings #1, the original answer to the question is that WCF RIA Services was the DomainDataSource. The problem is that even before WCF RIA Services had been released to the public for the first time early users such as myself had already abandoned the DomainDataSource. Scott Barnes said recently in a comment to this blog that WCF RIA Services was created to solve a problem that didn't need to be solved. Perhaps that is what caused the blind men effect, since the official problem that was solved didn't need to be solved, WCF RIA Services became a solution in search of a problem.
Ok, so what problem did you need solved?
Back in mid-2008 I began the design process on a large scale Line of Business application written in Silverlight. The resulting application has an MDI layout that uses Telerik's Ribbon and Dock controls. It would be used to open hundreds of rows of data scattered over 70 different database tables, edit massive numbers of those rows, and then the user could either save all of the changes back to the database or cancel all changes at the click of a single button and partials saves must be prevented. Different users would have different security requirements so I needed to implement role based security. There were also large numbers of business rules that had to be enforced server side, however due to the complexity of the editing process the business rules also needed to be enforced client side in the UI so that the users would get instant feedback on business rules issues. So to recap, the problems I needed to solve are:
- Client side change tracking for entities
- Efficient loading of large numbers of entities both in row count and type of entity
- Business rules are needed both on the server and in the client
- I would really like to not have to write the business rules twice
- Role based security enforced on the server but also accessible client side.
- I want to use something LINQ based so that I can query for entities from the client.
- I am worried about allowing to much access to my database through those LINQ queries.
- I need strong support for Unit of Work.
I had been looking at using ADO.NET Data Services to supply the entities and the change tracking. However, Data Services (OData) transfers entities in an object oriented fashion where the resulting object graphs can change depending on how data was loaded. It also seemed to me that data services opened my database up for more querying then I was completely comfortable with. From a performance, usability, and security perspective, I was close to switching back to plain WCF services. That is when I saw a demonstration of WCF RIA Services (known as just Alexandria at the time) at that years PDC. I contacted the presenter to request early access to the code and I haven't looked back since. As I said above, my application didn't really have master detail screens so the DomainDataSource didn't really fit my needs. It was all of the other parts WCF RIA Services that made it exact library I needed for my application.
- It has robust client side change tracking for entities
- RIA Services uses foreign keys to connect objects intead of object relationships like Data Services. That means it has no problems dealing with large numbers of rows and large numbers of entity types. At least, not until you start getting into >10,000 rows in memory.
- With RIA Services, you write your business logic on the server side and it is then automatically copied into the client layer.
- RIA Services enforces role based security on the server and provides an AuthorizationContext to push role based security into the client side as well.
- RIA Services supports LINQ queries...
- ...but it limits those queries to further filtering of the query exposed by the server.
- Unit of Work is a central design element of WCF RIA Services
Ok, so what is WCF RIA Services?
WCF RIA Services is a class library that supports the creation of an n-client, n-tier business logic layer. Two important aspects of WCF RIA Services is that it uses foreign-key based domain models and is designed around the Unit of Work pattern.