This is the penultimate chapter of this book in which we will explore how we can consume WCF 4.5 RIA and RESTful services using Silverlight 5.
In this chapter, we will cover the following points:
Silverlight (codenamed Windows Presentation Foundation/Everywhere or WPF/E) is a browser plugin. Silverlight is a client-side technology that provides support for RIA. It can be used to enhance the look and feel of web-based applications. The new versions of Silverlight contain enhanced features for building RIA-based business applications and rich media applications. Cross-browser and cross-platform compatibility and awesome support for rich graphics and animation are some of the striking features of Silverlight. Also, it runs in a sandbox environment—a subset of the WPF Framework.
The newer versions of Silverlight provide great support for Printing (including virtual print preview), COM Automation, Web cam and microphone, MEF (managed extensibility framework), and WCF 4.5 RIA Services. On a different note, the performance of Silverlight 5 applications has been optimized to a great extent.
WCF 4.5 RIA Services provide a framework that helps you to connect .NET client objects with .NET server objects using WCF 4.5. The newer version of Silverlight provides support for WCF 4.5 RIA Services. Note that WCF 4.5 RIA Services (formerly known as .NET RIA services) exposes data in an optimized .NET Binary format or ATOM, JSON, or in an OData format to the Silverlight application. WCF 4.5 RIA Services simplifies the development of RIA applications, that is, applications designed using technologies like Silverlight 5. RIA services provides you with a framework that eliminates the need of duplicating your middle-tier components.
Silverlight provides excellent support for developing the next generation of cross-browser and cross-platform Rich Internet Applications (RIAs). It facilitates the design and development of engaging, interactive user experiences for web and mobile applications. However, Silverlight 5 looks like the last release of Silverlight from Microsoft, and HTML 5 will be the choice going forward.
The choice between opting for Silverlight 5 or HTML 5 depends on many factors. If you are creating a Line of Business Application (LOB), you can choose Silverlight 5 and leverage its data binding features. On the contrary, if you need applications where images, links and textboxes, animations, and interactivity is needed, HTML 5 is a better choice. However, Silverlight 5 is better suited for intranet applications rather than web-based applications. Also, note that Silverlight 5 is only supported on Windows Phones.
The following are the new features added to Silverlight 4 and 5:
DataContextChanged
event, text tracking, improvements in text rendering, layout, clarity, and so on. In Silverlight 5, you can set the default filename when using the SaveFileDialog
box using the DefaultFileName
property. Here is how you can use it:SaveFileDialog fileDialog = new SaveFileDialog(); fileDialog.DefaultFileName = "Demo.txt"; fileDialog.ShowDialog();
.xaml
file, and you can use XAML to separate the user interface definition of your applications from the runtime logic by using code-behind files.DataType
property to the data template, instead of attaching the data template to every control in your page. Here's an example of a code snippet that illustrates this:<ListBox x:Name="users"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding FirstName}" FontWeight="Bold" /> <TextBlock Text="{Binding LastName}" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
Mark-up extensions is a feature that enables you to execute code at XAML parsing time . These include {Binding}
, {StaticResource}
, {RelativeSource}
, and so on. You can also create your own custom markup extensions.
dynamic excelObject = ComAutomationFactory.CreateObject("Excel.Application"); excelObject.Visible = true; dynamic workbookObject = excelObject.workbooks; workbookObject.Add(); dynamic sheetObject = excelObject.ActiveSheet;
dynamic wordObject = ComAutomationFactory.CreateObject("Word.Application"); wordObject.Documents.Add(); wordObject.Visible = true;
ApplicationManifest.xaml
file, so that you can leverage the elevated permissions while installing and using out-of-browser applications.<OutOfBrowserSettings.SecuritySettings> <SecuritySettings ElevatedPermissions="Required" /> </OutOfBrowserSettings.SecuritySettings>