What is Silverlight?
In this lesson of the Silverlight tutorial, you will learn...
- About the history of Silverlight.
- About the Silverlight architecture.
- Which environments support Silverlight.
This lesson will present you with a high-level overview of Microsoft Silverlight.
An Overview of Silverlight
Silverlight enables development of the next generation of Microsoft .NET-based media experiences and rich interactive applications (RIAs) for the Web. Silverlight is delivered as a cross-platform and cross-browser plug-in that exposes a programming framework and features that are a subset of the .NET Framework and Windows Presentation Foundation (WPF).Support
The industry has been abuzz about Silverlight since the beginning of 2007 when Microsoft began demonstrating its power at developer conferences. In fact, no other development technology has been so highly anticipated since the arrival of the .NET Framework and Silverlight resources and examples abound on the Web. To spark developer interest in Silverlight, Microsoft launched several community Web sites dedicated to Silverlight development including the Silverlight home page (http://www.microsoft.com/silverlight) and the Silverlight.net community Web site (http://silverlight.net).Early Adopters
In response to the overwhelming developer community anticipation for the arrival of Silverlight, many developers and companies have become early adopters of the technology.Some example sites are listed below:
- World Series of Poker
- Discovery Channel
- The Emmys
- Home Shopping Network (HSN)
- World Wrestling Entertainment (WWE)
- Fox
- XBOX 360
- Netflix - uses Silverlight to allow subscribers to instantly watch movies on their PCs or Intel-based Macs.
The .NET Framework
Microsoft introduced the .NET Framework in 2000 as a new approach to software development. The .NET Framework borrowed ideas from the best practices in the software industry as well as brought new ideas to the table in an effort to meet developer needs and requests.Virtually all programming languages manage data at some point. The primary reason that communication between applications created using C++, Visual Basic, Visual FoxPro, and other languages was difficult was because each language stored data being managed in a unique set of data types. For example, an integer in one language may not represent an integer in another language. Data needed to be converted to common data types to communicate between languages.
The .NET Framework introduced a common set of data types (the Common Type System) that is used by all .NET-compliant languages (C++, Visual Basic, C#, etc). Thus all languages can easily intercommunicate. Furthermore, all .NET-compliant languages render a common result when compiling code, Microsoft Intermediate Language (MSIL). (see footnote) MSIL can be deployed to any platform running the Common Language Runtime (CLR). Currently, the CLR is only available for Microsoft Windows although an open source version of the CLR was created for Linux (called the Mono Project). Code written by using the .NET Framework is compiled instead of interpreted resulting in much better performance than Java and competing technologies.
Microsoft took the Web development industry by storm with their .NET upgrade to ASP. ASP.NET put a new face on Web development through a compiled code architecture and improved state management and it provides access to the full functionality of the .NET Framework. ASP.NET is built around XML, supports the latest Web development standards, and allows for the creation of advanced Web Services.
The .NET Framework also provides improved data access and database integration through ADO.NET. For more information, see MSDN.
There are many more features and benefits of the .NET Framework than those mentioned here. The .NET Framework has become the leading software development environment available.
Introducing Silverlight
What's New in the .NET Framework
As of the writing of this course, version 3.5 of the .NET Framework has been released. Version 3.5 includes features that encompass all facets of Windows, Web, and network development:- Includes just under 10,000 classes, methods, and properties.
- Complies with the latest Web development standards.
- Introduces revolutionary technologies used in Windows Vista development, rich media and user experiences, workflow management, security and authorization, and complete distributed communication protocols.
- Windows Presentation Foundation (WPF)
- Windows Communication Foundation (WCF)
- Windows Workflow Foundation (WF)
- CardSpace
Windows Presentation Foundation (WPF)
WPF is used to develop elaborate user interfaces like those that adorn Windows Vista and managed advanced media streaming and integration. WPF is the a complete revamp of Windows Forms so that user interface, graphic, and media development is now designed around the .NET Framework.Windows Communication Foundation (WCF)
WCF encompasses the ASP.NET Web Services and .NET remoting functionality that was contained in the .NET Framework 2.0 as well as new communication technologies.Windows Workflow Foundation (WF)
WF is used to model complex workflow processes.CardSpace
CardSpace is the embodiment of new security and user authorization functionality.ASP.NET AJAX
ASP.NET AJAX was developed to improve performance in the browser by making post backs and calls between the browser and server asynchronously. ASP.NET AJAX uses new built-in types and controls and JavaScript.Both ASP.NET and ASP.NET AJAX are heavily dependent upon the ASP.NET page event life cycle, are tightly coupled to the server, and have a tough time competing with advanced, media-rich plug-in solutions such as Adobe Flash. Additionally, it is difficult to create Web applications that offer a consistent experience across all supported browsers and platforms by using ASP.NET and AJAX. In 2006, Microsoft began developing a solution to extend into the browser and offer media experiences more robust than competing plug-in solutions.
In 2007, Microsoft introduced Silverlight. (see footnote) Silverlight is a free plug-in that encompasses a subset of functionality from the .NET Framework and WPF. In a manner similar to the JVM (see footnote), Silverlight runs in the browser as a "sandbox" - a secure zone installed into the browser that accommodates Silverlight functionality while completely protecting the host platform from any possibly adverse actions performed by Silverlight.
Silverlight Architecture
Unlike ASP.NET, the bulk of Silverlight processing occurs on the client machine thus decreasing server resource utilization and improving the Web experience on the client. The figure below shows the difference between ASP.NET processing and Silverlight processing:When a client initially attempts to run a Silverlight application, if the Silverlight plug-in has not been installed on the client machine, it will be downloaded and installed. Upon subsequent requests to run the application, the application will instantiate on the client machine and make requests for resources from the server only when necessary. The Silverlight plug-in can be thought of as a scaled-down version of the full .NET Framework. It only contains those classes and functionality that are applicable to a Silverlight Web client and those were streamlined and optimized for use on the Web client machine.
Silverlight was designed using the same design paradigm as ASP.NET. Each page of a Silverlight application includes an associated code behind file that includes the code that handles events fired by the page. Silverlight resembles WPF in that it uses Extensible Application Markup Language (XAML) to construct the user interface (presentation layer). As Silverlight applications are composed of text-based files that include markup and code, they can be created using any text editor; however, more advanced tools and development environments such as Visual Studio or Expression Blend simplify the task significantly.
Silverlight Technologies
Version 1.0 of Silverlight used JavaScript and supported the industry-leading Windows Media Services enabling delivery of audio and video that includes 2D and vector graphics.Version 2 includes all features of version 1.0 and:
- support for the .NET Framework.
- support for .NET-compliant programming languages such as C#, Visual Basic, Python, and Ruby.
- support for database operations and language-integrated query (LINQ).
The diagram located at ClassFiles/WhatIsSilverlight/Demos/SilverlightTechnologyMap.gif gives a broad picture of the technologies to be supported by Silverlight version 2.
Silverlight Hosting
Microsoft Silverlight functionality is completely encapsulated within the Silverlight plug-in. Web applications typically require the server hosting the Web application to meet minimum requirements. Silverlight applications simply require a Web server to be equipped as they would be for hosting HTML documents. Silverlight applications can be hosted on any Web server accessible to the target audience. The two most commonly used Web servers are Microsoft Internet Information Server (IIS) and Apache.Executing a Silverlight application on a Web client machine is a two step process. First, the application will detect if the Silverlight plug-in is installed on the Web client machine. If the plug-in is not installed, the user will be prompted with an option to download the plug-in. If the user opts to do so, a request will be made of the Web server to download and install the plug-in. The Silverlight plug-in is embodied in a .dll executable file that is loaded into the Web client browser memory once installed. The only interaction required by the Web client when installing the Silverlight plug-in is to grant permission for the plug-in to be installed. Various Web servers, including Microsoft Internet Information Server (IIS), may require slight configuration modifications so that the Silverlight executable file will be downloaded to the Web client when requested.
Second, once the Silverlight plug-in is installed on the Web client machine, the Silverlight application itself must be downloaded. A Silverlight application may consist of many types of files. Slight configuration modifications may be necessary on the Web server, such as MIME types, so that XAML and XAP files are associated with Silverlight and downloaded correctly to the Web client machine when requested.
Once the Silverlight plug-in is installed on a Web client machine and a Silverlight application is downloaded, the Silverlight application is then hosted on the Web client machine. There are some requirements necessary for the Web client machine as discussed in the sections below, however all media players, audio and video codecs, compilers and the runtime are encapsulated in the Silverlight plug-in.
Supported Platforms
Silverlight can be installed on Windows and Macintosh machines. Silverlight applications run within the confines of a plug-in. There are many benefits to using a plug-in with the primary benefit being consistency across implementations. A plug-in application can provide a consistent result in every instance where it is supported. Other plug-in solutions, such as Adobe Flash, have become popular due to consistency across implementations. For instance, a plug-in application should deliver a consistent result regardless of whether it is displayed using Internet Explorer on Windows or Safari on a Macintosh.Silverlight 2 is currently supported on the platforms discussed below. (see footnote)
Operating System | Browser |
---|---|
|
|
|
|
Linux
Many developers are unaware that a version of the .NET Framework exists for the Linux operating system. Linux is an open source operating system that is supported heavily in the online community. The version of the .NET Framework that supports Linux is named the Mono project and was also developed by the open source community. The developers of the Mono project keep the project close to in sync with the .NET Framework when updates are released by Microsoft and created an initial, limited version of Silverlight (called "Moonlight") that supports Linux in approximately 21 days! (see footnote) You can get up to date information on this project at http://www.mono-project.com/Moonlight.Future Platforms
The Silverlight plug-in renders graphics and multimedia using a vector-based graphics engine. Vector graphics can easily be scaled from very small displays to very large displays of varying resolutions with virtually no loss of image quality. Silverlight on a Windows Mobile device will accommodate delivering live, streaming, high quality video to smart phones and similar devices. The goal is to enable developers to deliver rich interactive applications (RIA) to any type of device.Microsoft has announced support for Silverlight on mobile devices with a limited initial support for Windows Mobile and the Nokia S60 models. You can learn more about this future support at http://www.microsoft.com/silverlight/overview/mobile.aspx.
What is Silverlight? Conclusion
In this lesson of the Silverlight tutorial, you- Explored Microsoft Silverlight at a high level.
- Studied some of the history leading up to the release of Silverlight.
- Investigated the architecture of Silverlight.
- Learned which operating systems and browsers support Silverlight 2.
...................................................................................................................................................................
Hosting Silverlight Content in ASP.NET 3.5
Microsoft provides templates to create managed applications using Silverlight 2. These templates are available when we install Silverlight Tools Beta 2 for Visual Studio 2008. In this article, we will explore the different types of Silverlight applications, the templates available, composition of a Silverlight Web Site and how to integrate Silverlight in your ASP.NET applications.
If you are new to Silverlight, then I hope you have gone through the previous articles listed below. If you haven’t I strongly recommend you do so.
The Silverlight 2 Beta 2 (S2B2) contains two ASP.NET server controls: the ‘Silverlight’ and the ‘MediaPlayer’ control. The Silverlight control lets you embed XAML content into an ASP.NET page. The MediaPlayer lets you display media like the .wma and .wmv files into your site.
Prerequisites to use the templates: The following software is required to create and run Silverlight in ASP.NET website :-Silverlight 2 Beta 2, Visual Studio 2008, Microsoft Silverlight Tools Beta 2 for Visual Studio 2008 over here and ASP.NET 3.5 Extensions.
Note: If you already have Silverlight 2 Beta 1 installed on your machines, then before installing Silverlight Tools Beta 2, make sure that you have uninstalled KB949325, which gets installed during Silverlight Tools Beta 1. Also note that you cannot install S2B2 Tools on Visual Studio 2008 RTM Express editions.
To uninstall the update KB949325 on Windows Vista, go to Control Panel > Uninstall a Program > View installed updates > look out for your version for Visual Studio 2008 > Choose the update KB949325 > Uninstall.
Once you have Silverlight Tools Beta 2 for Visual Studio 2008 installed, you will get the project templates for C# and for Visual Basic to create a managed application based on Silverlight 2. Let us see how to use those templates and integrate Silverlight with ASP.NET.
Step 1: Open Visual Studio 2008 > File > New Project > Select the language (C# or VB) > Select ‘Silverlight’ in the Project Types > from the templates, select ‘Silverlight Application’.
Note: If you are unable to view the templates, you do not have Microsoft Silverlight Tools Beta 2 for Visual Studio 2008.
Step 2: Type a name (MyFirstSilverlightApp) and location for the project and click ok.
Step 3: The ‘Add Silverlight Application’ box appears with two types of host to choose from. You can either host the Silverlight content in an ASP.NET web site that can contain server-side code or choose to host it in a HTML web site. We will choose the first option ‘Add a new Web to the solution for hosting the control’ and the project type as Web Site and click OK.
Step 4: You will now observe that two projects have been created: MyFirstSilverlightAppWeb and MyFirstSilverlightApp. Let’s quickly dissect the two projects and see what is in each of them
MyFirstSilverlightAppWeb
ClientBin – Initially the folder is empty. But once you compile the application, it will contain a .xap file, in our case MyFirstSilverlightApp.xap. A .xap file is nothing but an archive file which contains XAML, some resources and server-side code. When the application is run, the Silverlight plug-in extracts and executes the contents of this archive file.
Default.aspx – an empty .aspx page.
MyFirstSilverlightAppTestPage.aspx – ASP.NET Test page which hosts the Silverlight content
MyFirstSilverlightAppTestPage.html – HTML Test page which hosts the Silverlight content.
Web.config – ASP.NET 3.5 Extensions settings along with the other website configuration settings.
MyFirstSilverlightApp –
App.xaml and App.xaml.cs – The App.xaml is required to configure your Silverlight application. You can also declare resources that will be available in all pages of your application.
Page.xaml and Page.xaml.cs – Contains the UI and the C# code to run the Silverlight application.
Note: VB.NET users will have the extension as .vb.
Step 5: If you open up your MyFirstSilverlightAppTestPage.aspx page, you will see syntax similar to the following:
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls"
TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" style="height:100%;">
<head runat="server">
<title>Test Page For MyFirstSilverlightApp</title>
</head>
<body style="height:100%;margin:0;">
<form id="form1" runat="server" style="height:100%;">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div style="height:100%;">
<asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/MyFirstSilverlightApp.xap" MinimumVersion="2.0.30523" Width="100%" Height="100%" />
</div>
</form>
</body>
</html>
If you recollect, I had spoken about the <asp:Silverlight> control that lets you embed XAML content in an asp.net page. The <%@ Register Assembly="System.Web.Silverlight" ..> points to the Silverlight library containing the <asp:Silverlight> control. The <asp:Silverlight> control contains an attribute called as ‘Source’. The source points to the .xap file contained in the ClientBin folder. And the .xap contains the functionality (XAML) that you have built in your MyFirstSilverlightApp project (contains the Page and App.xaml).
When the application is run, both the projects are compiled and the Silverlight assembly is copied into the ClientBin folder.
I hope you get the connection now and how a Silverlight control is hosted on an ASP.NET page. The Silverlight team has made it very easy for us and has provided the plumbing by default.
Step 6: Let us quickly add some functionality in our Page.xaml file. For demonstration purposes and to keep things simple, I will add a simple button control and display it on the asp.net page.
<UserControl x:Class="MyFirstSilverlightApp.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<Button x:Name="myButton" Content="Click Me"/>
</Grid>
</UserControl>
The Silverlight pages are actually usercontrols. The Grid, StackPanel and Canvas are parent controls within which you host other controls. For eg: Here we have added a Button inside the Grid control. After adding the button control, build the application.
Step 7: Right click MyFirstSilverlightAppWeb >Set as startup project. Now run it. You will see the button control hosted in the ASP.NET page.
I understand that this was a very basic demonstration of hosting Silverlight content in an ASP.NET page. As we will move ahead, we will learn how to do more advanced stuff like handling events, hosting complex controls, creating our own controls, deploying Silverlight assemblies, role of IIS and interacting between ASP.NET and Silverlight controls. Till then, keep the learning drive on and Happy Coding!! I hope this article was useful and I thank you for viewing it.
.................................................................................................................................................................
0 comments:
Post a Comment