This is a mirror of official site: http://jasper-net.blogspot.com/

MVVM Light template and WCF services (or any ASP.NET application for that matter)

| Wednesday, February 1, 2012
I was recently made aware of a couple of people having issues with WCF services (or ASP.NET applications) when using the MVVM Light project template for Silverlight. There is a blog post and a StackOverflow question, so what exactly is happening there?

Well in fact it is pretty simple when you know how Silverlight connects to web services. Due to the security model of Silverlight, the application cannot connect to a web site if it is not originating of this very website. In laymen’s terms, it means that the application can only connect to a web server if it also comes from the same webserver. For example, if the Silverlight application is served by http://www.galasoft.com, it won’t be able to connect to, say, http://www.cnn.com without getting an exception. We talk about cross-domain access restrictions.

Of course there are ways around that, for instance a website can specifically give access to Silverlight applications through a configuration file.

In the case that concerns us, it is exactly what is happening. You see, the MVVM Light Silverlight project template creates a Silverlight application without an ASP.NET host. I didn’t add one because I didn’t want to complicate the template too much. And also, to be honest, because adding a web project is super easy, but of course only if you know how to do, and this is exactly what we will do here!
Creating the application

The steps to create the application and the WCF service are as follows:

    Create the MVVM Light application using the MVVM Light project template for Silverlight.
    Right click on the solution in the Solution Explorer and select "Add, New Project from the context menu.
    From the WCF category, select a WCF Service Application and create it.
    Build the application.
    Right click on the MVVM Light project and select Add Service Reference from the context menu.
    In the Add Service Reference dialog, click on Discover.
    Make sure that the found service is the one you want to connect to, and click on OK.
    In the MVVM Light application, open the file Model/DataService.cs and modify the code as follows:

Read more: Laurent Bugnion (GalaSoft)
QR: mvvm-light-template-and-wcf-services-or-any-asp.net-application.aspx

Posted via email from Jasper-net

0 comments: