Thursday, 6 May 2010

RAD development in SL4

It is very easy to develop a simple silver light page which does not have any complicated logic without writing a single line code (as my friend put it). Yes it is very easy. But there is another question, if you are simply displaying a data from data source then do you need to follow MVVM model? You could but I do not think it is required since there is no code involved in VM. This is simple forms over data pattern.

In SL4, at your server side, create the Data Model and associate it with a service.  Build the solution. Now go to the client side and under Data there is an option to show the Data Source. From the data source, under domain services, drag the data service you want and drop in the grid control, whola that is it. Now if you run the program it will show you a simple data grid with the data from the domain service.

Couple of things you have remember if you are going in this path. The first and foremost, is the authentication and authorization.  If you do not care about the authorization then you are ok, if not, build the base authorization service and reuse it in all the domain services by adding [RequiredAuthentication] attribute. In the client side also create the main page which knows user information and passes to authentication service before you do data binding.

Second issue that you might run into is the amount of data that is passed over wire. So apply some filtering to the data before you return all the data. You can do the filtering at the server side or on the client side. You can do the filtering in the XAML itself. The simple solution is to add the filter based on some controls. By adding some controls, which binds the values to filtering logic in the data grid will bring only the data you want to show. You can read more about how to apply filtering on XAML at this link.

Tuesday, 4 May 2010

WebContext and how to make sure client code gets it

When you create RIA services, you want to make sure the ‘WebContext’ is available for the clients to consume the services. WebContext is created by Visual studio from the web project you are pointing to in WCF RIA link. Here are the couple of things you need to do to make sure you are not going run into ‘WebContext’ not found compilation error.

1. First and foremost, check the client side project property and make sure under ‘Silverlight’ tab, the last option ‘WCF RIA Services link’ is pointing to the correct web service project.

2. Enable ‘Show All Files under Solution explorer and find the ‘Generated_Code’ folder and remove everything from there.

3. Restart VS2010 (some times it works too, at least when I was testing with Beta, on some occasions, restarting VS IDE resolve the problem.)