OpenLightGroup Blog

rss

Blogs from OpenLightGroup.net


Using WCF RIA Services With LightSwitch: I Know You're Scared, I Understand

First item of business, you’re not wrong. If your code works, and you are happy with it, march on with my blessing!

This is not about telling anyone that they “are wrong”. It is written only to encourage you to consider using WCF RIA Services in your LightSwitch applications.

 

The “MVVM WARS”

I was a soldier in what I call “The MVVM Wars”. On one side you had the “MVVM purists”. They insisted that you must write unit tests for all your code, and that you must implement interfaces and “mocks” so your MVVM code was “testable”. I was on the other side, I looked at the huge complex code that the purists insisted was “correct”, and it was not something I felt I would enjoy programming. I wrote a large number of articles over a period of years to demonstrate a method of using MVVM that for me was “enjoyable to program”.

My point is, I know what it feels like when other programmers tell you that you are wrong. This makes you defensive, because it is as if they are denying you the right to create your “art”. If you rather continue with your current techniques, please continue to do so and remember, I am not saying you are wrong.

 

Why You Won’t Use WCF RIA Services

Ok now we got that important part out of the way, let us now discuss why *I* would not use WCF RIA Services until recently. Yes, let me try and make my point by first calling myself on the carpet. I have been using LightSwitch for over a year, and the day I made my first LightSwitch WCF RIA Service was… only two months ago!

Now, my reasons for not using WCF RIA Services with LightSwitch may be different than yours:

  • I had a really bad experience with WCF back in 2008 when I tried to incorporate it into the DotNetNuke IWeb project. I read books on the subject and created contracts, meta data, ect just to perform functions that were quite easy using normal web services (you will notice that all my Silverlight articles used standard .asmx web services not WCF).
  • I did not want to complicate my LightSwitch application with code that I needed to maintain in more than one project.

Here are some of the reasons you may not want to use WCF RIA Services with LightSwitch:

  1. Programming is scary! Once you get a hang of the LightSwitch UI, you feel that it is something you can handle. A WCF RIA Service is a blank page and no safety net (well there is the compiler, but that’s only a safety net that an experienced programmer can appreciate).
  2. You can live with the limitations LightSwitch has.

 

LightSwitch Is A Sportscar – Drive Fast!

Reason number two is what motivated me to write this blog post. Because I believe that when you use WCF RIA Services and Silverlight Custom Controls, there is nothing that LightSwitch cannot do, that you could do with a normal Silverlight application.

LightSwitch is nothing more than a application builder to create Silverlight applications. It contains screens to assist in numerous tasks, but the LightSwitch team knew it was impossible to make a tool that was easy to use AND able to perform any task. From the start they designed it to allow you to use any WCF RIA Service for the input of data, and any Silverlight control to display the UI. LightSwitch is the thing that’s sits in the middle.

If you avoid using WCF RIA Services with LightSwitch, it would be like buying a sports car and never going past 3rd gear. LightSwitch was designed to be used with WCF RIA Services. This is what allows LightSwitch to be used for professional applications.

I have mostly concentrated on creating Silverlight Custom Controls with LightSwitch. I did not try to create any large applications until LightSwitch was finally released a few weeks ago. It was then that I discovered that the only way to get past any limitations was to use WCF RIA Services.

 

Why You Want To Use WCF RIA Services

Simply put, there are limitations to LightSwitch if you do not use WCF RIA Services. Here are some things that it wont do:

The list goes on and on. LightSwitch was designed to handle the majority of situations that a Line-Of-Business (LOB) application requires without needing a WCF RIA Service, not All of them.

 

The Challenge

Are you up to a challenge? Walk through this tutorial:

WCF RIA Service: Combining Two Tables

And then decide if WCF RIA Services with LightSwitch are for you.

That’s it.

Have a great day! Smile

 

Further Reading





Comments are closed.
Showing 2 Comments
Avatar  Mark 5 years ago

Thanks for the article!<br /><br />This is important to know for what I am doing. My boss wants a simplified environment that just works as it is lower budget, and it needs to be easily picked up by the next person to manage the system.<br /><br />Thanks

Avatar  Petr Antos 6 years ago

Hi Michael,<br />I discoveret this your article just today, and as I am also big fan of LS from start (and in fact long before it was announced I used quite similar LOB apps tool in MS-DOS world ...really :-), I am glad to see you are great supporter of community, although at first I mentioned you primarily as SilverLight guy too :-).<br /><br />Yes, key to full power of LS is making our own WCF RIA Services, and will be fine if you cover the simplest way how to expose/describe it for community of bussines users, as using EntityFramework isnt so much complex, if we master some concepts. Writing of our DomainService is also VERY easy even in pure LightSwitch - you for sure found my recent articles too:<br /><a href="http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/6af12740-c008-4249-9f14-2f7ab791fabf" rel="nofollow">social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/6af12740-c008-4249-9f14-2f7ab791fabf</a><br /><a href="http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/1c400973-a3ad-4ca2-bce7-0a26aa0b1457" rel="nofollow">social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/1c400973-a3ad-4ca2-bce7-0a26aa0b1457</a><br /><br />As far as creating custom WCF RIA DomainService is so simple, it will be great to extend this approach and enable it for more general use, because this really allows ALL. LS client code runs in context of SilverLight/CoreCLR (based on NET Compact Framework in fact) and is intentionally sandboxed even in "out-of-browser" app, but server code can do everything, even if deployed on single machine, for "pure-desktop" application, as long as anybody needs this today :-)<br /><br />To make own DomainService, we need only own "namespace" with some custom "code-first" Entities and DomainService inherited class(es) with some "Selecting" query methods in it (they are returning custom EntitySets) and/or "Modifying" methods (they are discovered by conventiontions/prefixes Insert*/Update*/Delete*). And thats all. It cannot be too complex even for bussines users AND in pure-LightSwitch IDE, as long as there will be proven templates and tutorials, which YOU can do very well :-)<br /><br />Have a nice weekend! (here in Prague is VERY HOT day:-)<br /><br />Petr<br /><br />