The Register® — Biting the hand that feeds IT

Microsoft's Silverlight 4 - Flash developers need not apply

The dark side of .NET improvements

By Tim Anderson • In Developer • At 20:36 GMT 3rd December 2009

Review

Microsoft's Silverlight 4 shows remarkable progress since version 3, released in July. The pace of development shows Microsoft is serious about making this work - but is it delivering something developers can use?

The answer is a guarded "yes". Version 4 is a huge improvement, resolving many of the most frustrating aspects of its predecessor, though there are still reasons for caution.

There are three broad groups of customers Microsoft hopes to capture with Silverlight. The first is internet broadcasters, where the company has had limited success so far. In the USA, Major League Baseball reverted to Adobe Systems' Flash after a brief dalliance with Silverlight, and in the UK ITV also dropped Silverlight after using it for its ITV player.

Flash is hard to shift, with greater penetration in web browsers, much better device support, and a strong industry alliance in the form of its Open Screen Project. Silverlight 4 adds DRM for H.264 content, along with offline DRM, but success here is more about establishing partnerships and getting the runtime deployed than it is about adding features.

The second group is web designers. This also is challenging for Microsoft. Many designers work on the Mac, whereas the Silverlight design tool, Expression Blend, works only on Windows. Further, Flash is already present on over 95 per cent of web browsers, where Silverlight can only muster around 45 per cent according to Riastats.com - though that figure took a lurch upward last month, partly thanks to an increased sample size.

Visual Studio and Blend integration

A right-click brings a Silverlight form from Visual Studio into design-tool Expression Blend

The third group is developers, especially those already familiar with Microsoft .NET and Visual Studio. This is where Silverlight 4 shines, and also where the company has given the product most attention. Silverlight 4 is part of the new .NET product wave, which includes .NET Framework 4 as well as Visual Studio 2010.

Visual-Studio thumbs up

This is the first Visual Studio with full Silverlight support, including a two-way visual designer and a variety of Silverlight project types. Microsoft has done a great job here, and working with Silverlight is smooth, especially when compared to the pain of earlier iterations. There are some important new controls, including a Rich Text control and an HTML control when working out of the browser, as well as limited clipboard support and access to cameras and microphones.

Setting up for the Silverlight beta involves three main components. First, you need a sacrificial machine or virtual machine. Install Visual Studio 2010, currently at Beta 2, and then the Silverlight 4 tools, which includes the runtime and SDK as well as the Visual Studio integration. Finally, you can add Expression Blend Preview for .NET 4.0. Visual Studio has a forms-oriented visual designer, whereas Expression is a rich design tool. I had to fiddle with the registry to get this working, but once set up you can open a Silverlight page in Expression directly from a right-click in Visual Studio, work on it there, and save it back.

Easy debugging

Visual Studio creates integrated Silverlight and Web application projects by default. This gets you a combined solution with easy debugging across both the ASP.NET web application and the Silverlight client, which is a real advantage for troubleshooting. Visual Studio has its own local web server for debugging. There is also an option to enable .NET RIA Services, a server piece that is now based on Windows Communication Foundation (WCF).

Microsoft generally demonstrates RIA Services in conjunction with the Entity Framework object-relational mapping layer, but this is not essential. I tested Silverlight 4 with a simple calculator application. First, I used the visual designer to create a form where the user can enter numbers, select an operation, and then click a Get Result button. Next, in the web application, I added a new Domain Service class, which is the foundation of RIA Services. I added a public DoCalc method and marked it with the [Invoke] attribute, meaning that it is automatically exposed to the Silverlight client.

When you compile the project, Visual Studio does some magic and generates a Silverlight proxy class. All remote calls are asynchronous, so you need to add a callback method to receive the result. Mine is called OnCalcCompleted. You can then call the remote function, passing the callback method as an argument:

Web.ServerCalc sc = new Web.ServerCalc();
sc.DoCalc(i,j,op,OnCalcCompleted,null);

It worked first time. RIA Services also supports user authentication based on ASP.NET's membership framework, and database batch updates using changesets, which allow the Silverlight client to send a set of changes together rather than piece by piece.

Exporting Silverlight results into Excel

Silverlight's new COM automation support lets you export results into Excel

The next task was to test Silverlight's new COM automation support, and give the user an option to export the result into Excel. This involves several steps. The first is to display project properties and check the option for out-of-browser support. This enables an additional option to require elevated trust, unlocking local file access as well as COM automation. I then wrote a few lines of code to automate Excel, using the new ComAutomationFactory. This code is resolved at runtime and uses the new dynamic feature of C#, for example:

dynamic Workbook = Excel.Workbooks.Add();

Getting the code right can be tricky, as there is no Intellisense help. The next step is to run the application, install it locally from a right-click menu option, and test the functionality, which in my case worked fine.

A strong feature of locally installed Silverlight applications is they can update automatically, though to get this you have to add a specific call to the CheckAndDownloadUpdateAsync method. Silverlight will then automatically install the latest version when online.

Tie-in payoff

The snag with the COM automation feature is it only works on Windows. In addition, although Microsoft has made some progress with Linux support by working with partners including Novell and Intel, it does not compare with the runtime for Intel Mac, which Microsoft builds itself. Another doubtful area is mobile. Microsoft is promising news on this at the Mix conference in Spring 2010, but it is a long way behind Adobe.

Microsoft is doing a superb job with Silverlight 4 for Windows developers. This is becoming an increasingly interesting runtime for both browser-hosted applications, and for desktop applications built according to the Internet model, with the added bonus of Intel Mac support provided you avoid the new COM features.

The dark side of Silverlight, though, is its bias towards Windows, its poor Linux support, and lack of a mobile option. Even so, this is a product that deserved the warm reception it received recently at Microsoft's Professional Developers' Conference. ®

42 comments

Next → Apple's App Store police relent on hardware images

Previous ← Linux kernel cured of remote panic-attack bug

Desktop version