All posts in Silverlight

I’m pretty often asked the question “Can I use real (as in coming from a database) data in my Silverlight application?” the answer is “of course”, although this requires a lit more work than any other technology (WinForms, ASP.NET, WPF) you could use. The reason for that is, that as you probably already know, Silverlight runs on the client, so you’ll need a way to move the data from the server to the Silverlight Client application.

There are a number of ways you can achieve that, like for example building a WCF Service and the necessary DTOs (Data Transfer Objects) to communicate between Silverlight and your Business Layer. There is though, a far more easiest way to achieve that functionality and that is using .

For those that haven’t heard about ADO.NET Data Services before, ADO.NET Data Services is a new part of the .NET 3.5 framework that supports exposing a data model (e.g. LINQ for SQL, Entity Framework, etc.) as a set of queryable REST endpoints. ADO.NET Data Services maps the four data verbs into the four HTTP verbs POST (Create), GET (Read), PUT (Update), DELETE (Delete).

Essentially it provides a way to use a data model across the firewall. It works by exposing IQueryable endpoints through a URI-based syntax allowing developers control over how the data is retrieved. In addition ADO.NET Data Services utilizes JSON and Atom as the serialization formats. These make it easy to consume in client-side interfaces like Silverlight and AJAX.

In order to use ADO.NET Data Services you’ll first have to create a Data Model. You can either use a Linq To SQL (it currently supports only read – you’ll have to implement updates) or an Entity Framework model. Once your data model is ready you can create a new Data Service in your Silverlight Web Site (Note: the data service won’t work if it’s implemented in a different domain than the one running the Silverlight application. Cross domain calls are disabled due to IE security) by right clicking on your project and selecting “add new ADO.NET Data Service”. Once the service is created you’ll have to specify the model type in the service code behind as well as the permissions the service will have on the data.

public class WebDataService : DataService< /* TODO: put your data source class name here */ >
{
    // This method is called only once to initialize service-wide policies.
    public static void InitializeService(IDataServiceConfiguration config)
    {
        // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
        // Examples:
        // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
        // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
    }
}

The next step is to create the service proxy classes in your Silverlight project. You can do that either by adding a service reference to your Silverlight application project or by using the DataSvcUtil.exe tool located in the C:WindowsMicrosoft.NETFrameworkv3.5 directory to create them and then copy them to your project. Typically you would call it by specifying the URI of the service, the name of the class file to create and what language to use:

DataSvcUtil.exe /uri:http://localhost:1025/YourService.svc
                /out:dataclass.cs
                /language:CSharp

You will also need to add a reference to the System.Data.Client.Services.dll assembly. This is the ADO.NET Data Services client library that allows asynchronous LINQ queries that are translated into the URI syntax automatically. Note that if you’ve installed Visual Studio 2008 SP1 this library is no longer compatible with ADO.NET Data Services and you’ll not be able to connect to your service. (read more about this here). Fortunately the guys in Microsoft have released an interim version of this assembly that works with Silverlight Beta 2 until Silverlight releases its next version. You can download this assembly from Mike Flasko’s blog.

The way you work with the referenced service is similar to the way you would normally work with an Entity Frameworrk Data model. You first instantiate a Data Context specifying the service URI and then you create a Linq query to fetch the data. Now normally, you could execute the query directly by calling something like ToList() against the query, that isn’t supported in Silverlight 2 Beta 2 though.  In fact, if you try you will simply get a NotImplemented exception. In order to execute these queries, you will need to cast the query into a DataServiceQuery.  The DataServiceQuery allows you to call BeginExecute to start an asynchronous query as seen below:

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
 
  NorthwindEntities ctx = 
    new NorthwindEntities(new Uri("/Products.svc", UriKind.Relative));
 
  var qry = from p in ctx.Products
             orderby p.ProductName
             select p;
  
  // Cast the query to a DataServiceQuery
  DataServiceQuery<Product> productQuery = 
    (DataServiceQuery<Product>)qry;
 
  // Start the execution
  productQuery.BeginExecute(new AsyncCallback(OnLoadComplete), 
    productQuery);
}
 
void OnLoadComplete(IAsyncResult result)
{
  // Get a reference to the Query
  DataServiceQuery<Product> productQuery = 
    (DataServiceQuery<Product>)result.AsyncState;
 
  // Get ther esults and add them to the collection
  List<Product> products = productQuery.EndExecute(result).ToList();
}

Once the query completes, it will call the OnLoadComplete method that was specified in the AsyncCallback.  In this method, you first grab the DataServiceQuery that you sent with the request then end the execution to retrieve the results.

While its not as straightforward as synchronous execution, the new ADO.NET Data Services certainly works well in Silverlight 2 Beta 2 and provides a great way to use existing or planned data models over Internet applications.


There were quite a few questions on my last Silverlight talk about Silverlight support in various Linux Distros.

Well today I read that a first source code release was made publicly available in order to encourage developers start playing with it.

To try out Moonlight, you have two options:

  • Media codecs: you must do your own build from source code.
  • No-media codecs: we provide one-click addins for Firefox that will install with no effort.

Firefox addins are available from http://www.go-mono.com/moonlight.

Source code for Moonlight is available from here. To compile Moonlight from source code follow these instructions.


Yesterday I had the chance to talk at a DotNetZone event about Building Rich Internet Applications using Silverlight 2.0. It went very well, people seemed to have an active interest on this new Technology and anxiously looking forward to build real word applications (like this healthcare one announced yesterday by Tim Sneath) with it.

My session was quite long (2.5 hours – thankfully no one slept during it ;-)) so I had the chance to talk about almost all of Silverlight’s features and give a lot of demos, after all events like that, where you speak to developers, is all about demos right 😉 The topics that I covered were:

  • An Introduction to Silverlight
  • Core UI Features
  • Controls, User Controls
  • Styles and Templates
  • Networking
  • Data
  • Linq
  • Isolated Storage
  • Browser Integration

You can find all the source code from the presentation demos as well as the ppt here:


I’m also planing on uploading my session recording (yes I’ve recorded the whole thing 😉 I just need to find some space and bandwidth on the web.

Stay tuned!


Protected: Silverlight Ajax Video Screencast

Categories: Expression Suite, Silverlight, Visual Studio
Enter your password to view comments.

This content is password protected. To view it please enter your password below:


Microsoft announced a bunch of cool new features in Silverlight 2, in this year’s Mix  conference. One of the most exciting new features is the Deep Zoom one.

Deep Zoom allows users to explore collections of super high resolution imagery, from a 2 or 3 megapixel shot from a digital camera to gigapixel scans of museum pieces, all without waiting for huge file downloads.  The simple zooming interface allows users to explore entire collections down to specific details in extreme close-up, all with fantastic performance and smooth transitions.

What you probably won’t know (at least I didn’t 😉 till today) is that there is a hosted Deep Zoom service where you could try out this new technology. So if you haven’t tried it yet I strongly urge you to give it a try, I did and am pretty excited about it.


You must all have seen by now the popular “Turning the Pages” British Library application. It’s probably one of the most impressive WPF applications, one that has been developed by Microsoft in partnership between the British Library and Armadillo Systems.

“The British Library have digitized the pages of fifteen of their most valuable works and created Turning the Pages, a browser-based WPF application that allows you to interact with these books in a virtual environment from the comfort of your home. You can open a book on your desktop and by clicking on a page, physically turn it in a 3D environment.”

What you probably don’t know is that this application has been recreated using Silverlight. Of course the experience is not the same as the one you can live with the WPF Version. The turning of the pages, for example, is done in 2D (as Silverlight has no support for 3D yet) and there is no refinement on the page when you zoom in on the page as there is in the WPF one. It’s clear advantage though is that it brings this experience on multiple platforms and not just the Windows one.

You can check out the WPF Version at http://ttpdownload.bl.uk/, while the Silverlight Version can be found at http://ttpadd.bl.uk/ttp_software/silverlight/default.html.


Protected: Great WPF applications

Categories: .NET 3.0, Silverlight, WPF
Enter your password to view comments.

This content is password protected. To view it please enter your password below:


December’s edition of the Greek PCMagazine is out and in it you’ll find my latest article on how to develop lean – mean web mashups, even without having to write code, for your web site using Microsoft Popfly. So if you’re interested go grab it at your local news stand.


Protected: Building the Web.Next Now

Categories: ASP.NET, Great Sites, MS Application Blocks, Silverlight, Web
Enter your password to view comments.

This content is password protected. To view it please enter your password below:


Working with popfly for the 2007 elections silverlight graph gave me a fare ground of understanding on using and developing with Popfly. So I thought why not  share this by making my first official screencast.

I’m glad to say that it’s now complete and you can see it from here:


Video: Create Rich Web Content Using Popfly

I need to apologize for the video quality, but this was the only way I could publish it. I’m still looking though for other places where I could post the high quality screencast (If you know a place please contact me).

So stay tuned…