O'Reilly logo

Data-Driven Services with Silverlight 2 by John Papa

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Silverlight 2 Features

Silverlight 2 introduced support for .NET code in Silverlight applications, but that is not the only major improvement it offered. Table 1-1 lists many of the major improvements to Silverlight 2, including several that are integral to developing data-driven applications with Silverlight. Table 1-1 singles out these specific features, as it is important to be aware of how they can help developers build solid, data-driven applications with Silverlight 2.

Table 1-1. Key Silverlight 2 features

New features in Silverlight 2

Notes

Framework languages and .NET support

Silverlight 2 includes a portion of the .NET Framework, and supports Visual Basic, Visual C#, IronRuby, and IronPython.

Data binding and notifications

XAML-based data binding and notifications through the INotifyCollectionChanged and INotifyPropertyChanged interfaces are now available in Silverlight 2.

Isolated storage

Silverlight 2 can store information in a protected area on a client computer.

Contractual and noncontractual data services: JSON, REST, SOAP, POX, and Atom-based RSS web services

Various data services are accessible via Silverlight 2. This makes reading data from web services simple.

Cross-domain network access

Silverlight 2 can access services that do not originate from the server hosting the Silverlight 2 application.

LINQ, lambdas, extension methods, and object initializers

LINQ to Objects, LINQ to XML, and LINQ to JSON are included in Silverlight 2 to define queries against complex data structures.

StackPanel, Grid, and Canvas layout support

Silverlight 2 introduces support for the three major layout panels native to WPF and XAML.

Suite of bindable controls and panels

Silverlight 2 introduces a wide array of controls that you can integrate into Silverlight 2 applications and bind to data sources.

Note

Originally, Microsoft was going to release Silverlight 2 as Silverlight 1.1, but with all of the improvements it made to the application, the company deemed the new version to be different enough to warrant its own major release number.

Looking at the new features in Table 1-1, it is obvious that Silverlight 2 boasts a lot of major new capabilities. It is important to touch on each enhancement that directly affects data-driven application development. We will explore many of these thoroughly in upcoming chapters, so for now I’ll cover them only briefly to introduce you to them.

Framework Languages and .NET Support

I cannot overstate the fact that developing a Silverlight application is much easier when you can leverage your existing .NET development experience. This starts with being able to write .NET code in the Silverlight client application to handle various aspects of that application, including event handlers, referencing the extensive .NET Framework, and creating complex user controls. The Silverlight 2 runtime contains a small but powerful subset of the .NET Framework library so that developers can take advantage of their .NET skills and transition to Silverlight 2 with minimal effort.

Self-Describing Data Services

Silverlight 2 can communicate with SOAP-based web services (e.g., using WCF or ASMX) to pass defined data structures between a Silverlight client and a remote server. These services expose a contract through WSDL with which the client can communicate by generating proxy classes. This contract defines the services that you can call and how to call them, and it exposes the data structures that you can pass into and out of the services. This is key to exposing web services that return or accept serializable entities as parameters. With contractual data services, Silverlight 2 can communicate with remote services that return entities from LINQ to SQL, NHibernate, the ADO.NET Entity Framework, or even custom domain entity models. It also opens the door to being able to communicate with third-party SOAP-based services that expose WSDL, such as Live Search.

Loose Coupling with Data Services

Silverlight 2 can also consume data services without generating proxy classes using SOAP, RSS, Atom, JSON, POX, or REST. Many sources of information are available that return data using a noncontractual service. For example, Digg.com, Amazon.com, Twitter.com, and Flickr.com all expose REST services that return XML. Silverlight 2 applications can request information from all of these services and integrate the results into an application. In Chapters 79, we will delve deeply into these areas, as well as discuss how to communicate with them across domains and how to manage the XML and JSON they may return via LINQ to XML and LINQ to JSON, respectively.

Control Model

The new control model that Silverlight 2 provides makes it much easier to write Silverlight 2 applications. You can organize the new controls within the XAML layout panels, such as Grid, Canvas, and StackPanel, to create rich interfaces. The controls support XAML-based data binding and dependency properties, which we will discuss in detail in Chapters 24.

Silverlight 2 introduced more than two dozen controls that you can use to build Silverlight 2 client applications. It offers layout panels such as Grid, StackPanel, and Canvas, as well as several input controls that you can customize using templates and styles. You can completely replace the content of some of the controls to achieve a more complex solution. For example, you can replace the header of a DataGrid control with a series of controls that allow you to sort the DataGrid. Or you can replace a button’s default look with another element such as an Ellipse and fill it with another FrameworkElement such as an image. Chapters 24 will dive deeply into the controls and explain how data binding works with them, as well as offer best practices for binding and presenting data. Figure 1-1 shows the controls available in Expression Blend 2 with SP 1 and Figure 1-2 shows the controls available in Visual Studio 2008.

Silverlight 2 controls shown in Expression Blend

Figure 1-1. Silverlight 2 controls shown in Expression Blend

Silverlight controls shown in Visual Studio 2008

Figure 1-2. Silverlight controls shown in Visual Studio 2008

LINQ to Objects and LINQ to XML

Silverlight 2 supports the use of LINQ to Objects, which can simplify the querying of data in arrays and collections in a Silverlight application. LINQ to XML (also supported in Silverlight 2 applications) is very useful when consuming noncontractual data services that return XML. The XML can be read into a variety of XML-consuming libraries, but consuming it with LINQ to XML’s objects allows you to query the XML using the familiar and powerful LINQ syntax. Also, with LINQ at your disposal you can combine XML and object data structures in the same LINQ query. Many of the examples in this book will use LINQ in some fashion to query data from XML or objects.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required