This article is more than 1 year old

Microsoft's Silverlight 4 - Flash developers need not apply

The dark side of .NET improvements

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. ®

More about

TIP US OFF

Send us news


Other stories you might like