views:

708

answers:

1

I just started learning Silverlight, and I'm wondering about the typical architecture of a Silverlight application and the workflow in the application (I'm using Silverlight 2, but will move to 3 any time soon).

In my test-application I currently only have the two default projects - MyProject and MyProject.Web. I'm familiar with the MVVM pattern, and have organized my code using this. However, I'm having trouble understanding what goes on the client and what goes on the server - and how do I define this? I'd guess the ViewModel layer is on the client - communicating with the Model layer being on the server. But how will they communicate? Using WCF? Should the server part of my application be defined in a separate project? And should the client part have a reference to this?

I ran into problems when I wanted to set my Model to communicate with a SQL Server using LINQ to SQL. "LINQ to SQL" items doesn't seem to be allowed in Silverlight projects, and if I add this to a separate Class Library Project I'm unable to reference this project from my Silverlight project as; "You can only add project references to other Silverlight projects in the solution".

Any information that might enlighten my understanding of the architecture and workflow is greatly appreciated. Thx.

+1  A: 

Windows Communication Foundation (WCF) is the way Silverlight communicates to the server. You can also look at the RIA framework currently in tech preview, which adds a layer between Silverlight clients and WCF web services for data validation, allowing the sharing of validation code (among other things).

Direct connections to databases are not possible from Silverlight - instead you need to use a WCF service via a web server to access your data. If you use old style ASP.NET web services, Silverlight wraps these for you into WCF-like wrappers when referencing those services.

Jeff Yates
Thx! This really cleared up the concepts for me. So - I typically have a separate WCF project then? Will this hold the whole model side of the MVVM pattern for me? Do I place the ViewModel on the Client side - in the Silverlight project? I see that the WCF project can't be referenced from the Silverlight project, but I guess I need no direct link between these? All communication is through REST calls?
stiank81
You host the WCF classes in an website project and then add a Service Reference from the Silverlight project to the website services. Silverlight will generate all the classes you need clientside to communicate with the service. You don't need to consider how that is sent unless you want more fine-grained control over the communication.
Jeff Yates
Service Reference - I see. Well, I know enough now for digging further into it. Thx for making things clear for me!
stiank81
You're welcome.
Jeff Yates