Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Silverlight for Dummies - Why Silverlight?

0.00/5 (No votes)
26 May 2009 1  
This article explains why Silverlight is needed. Explains the basic things which are required to understand the working of silverlight. Beginners must start with this article.

Introduction

This article explains about why Silverlight is needed, why we should move to Silverlight and it also explains about the relationship between Web Server, Web Browser and Silverlight.

Why Silverlight?

What made me really invest time in learning Silverlight? Hope this will be helpful for beginners who want to know about "Why Silverlight?"

I will try to write a post daily but my first post will concentrate on “What made me move to Silverlight?”. The second post will include more on the technical side of Silverlight. After a few posts, I will be writing one application which will help us to understand Silverlight starting from Login, WCF, Data Binding, Prism, ADO.NET Entity framework, which will give us a complete flow and help us to understand Silverlight. Please feel free to write to me at dhaneel.shanthpure@gmail.com for any suggestions or questions. Please do leave comments on the post.

So let’s start.

Before beginning to know more on Silverlight, first we should know:

  • Why Silverlight?
  • Importance of Silverlight?
  • Where to use?
  • Underlying architecture

Before I begin with any new language, I always want to know what language it is? How to use it? And what is the architecture behind it?

I will answer these questions with a case study. In that way, you all will understand it very clearly.

I got one project last year. The client need was to develop a website for some product which will have tree control, menu item, UI elements and business logic involved in it, etc. Then I took the project and started working on it.

I wrote JavaScript to do few things. When we had a small demo with the client, he was very upset and said “Is this a way to write JavaScript code? What code have you written?? Where are the namespaces?” They started shouting at me. They very well knew JavaScript and I never knew that there was anything called namespace in JavaScript! I started searching on the internet but couldn’t find any related information on JavaScript. From before, I always thought that JavaScript is a very simple language but I was 100% wrong. I always thought that very few people use JavaScript and never wanted to learn it because one of my college seniors said JavaScript is very simple language and he showed me the following program in JavaScript.

<html>
<head>
<script type=”text/javascript”>
function load()
{
alert(’Hello World..’);
}
</script>
</head>

<body onload=”load()”>
</body>

</html>

This used to show me Hello World when I used to open it in the browser. After that, I never bothered to learn more on JavaScript. But you can’t believe JavaScript is the most widely deployed application on the Internet!!! Can’t believe me?? I will tell you how…

Before that, please understand that JavaScript is nowhere related to Java language. The person who was developing JavaScript at netscape got inspired by Java so he used few tags from Java and then named it LiveScript but when they wanted to collaborate with Sun Microsystems, then they named it as JavaScript. I don’t want to discuss more on this. But just remember one thing that Javascript and Java are totally different. If you want to know more, here are the links… They say Javascript is the World’s Most Misunderstood Programming Language.. J ..

Every machine Windows, Mac, Linux has a web browser in it?? And every web browser has JavaScript in it. So JavaScript is the most widely deployed application in the internet. You can just code using HTML and JavaScript and there is no need to worry about deploying on client’s machine.

I will come back to my problem.. :-) .. After getting yelled at from my client, I started looking for more information on the internet. I asked the client to give me some time so that I can learn about JavaScript. I didn't find any good article on the internet about JavaScript which told anything about namespaces. I took complete 30 days to learn about JavaScript. I really got shocked when I got to know that we have inheritance, classes, etc. in JavaScript. At that time, I found that on Yahoo developers site, Douglas Crockford was doing a hell lot of things on JavaScript and I think he is a real genius. If anyone is interested in knowing more about JavaScipt, here is the link:

There are some 4 videos by Douglas Crockford — “The JavaScript Programming Language”.

Here you won’t find simple Hello World Stuff. :-)

Again back to my problem. I learned JavaScript and started coding for my client. Each UI control used to take hell lot of time for me as I was a beginner. As they were paying well enough, I thought I will buy controls from another company. There are some companies like infragistics[http://www.infragistics.com/] where you can buy controls. But on Yahoo developers, you can find loads of free JavaScript stuff. So make sure you first look at it and then write your own or buy from others.

Somehow I managed to complete the project and delivered it. The same client again came to me and started asking me that he will be giving the demo of this application to his client and needs a good UI and said he will pay me for that. Then I said ok, I will look into it then I got to know that in Adobe Flash, we can do a lot of good UI stuff, animation, etc. I had very little time to deliver this, therefore started searching for a Flash designer. Then I found one who did his job well. He created a very nice UI with Menu Dropping from top and very good jazzy user interface. Then the biggest problem was waiting for me. How will I call events from Flash??? Damn…. There is something called action script in Java which will do that work. I failed to find an action script programmer. People who know Flash just know UI and animation they don’t know about action script. I struggled a lot to find one developer and get it done. Finally I ended up learning:

  • ASP.NET
  • JavaScript
  • Flash
  • Action Script

All need different expertise and I got really very frustrated learning them. I know everything but I am not a master in any one of those. Take any of the above mentioned languages. They need more time and effort to get expertise in them. All I was doing was wasting time and money in outsourcing each and everything to another company and not giving the client a very good product.

Then I found out that Microsoft is coming with a product called Silverlight. They were very well aware about the problem developers were facing. They bundled everything into Silverlight. To make it simple to explain, Silverlight is nothing but a replacement for JavaScript, Flash (or any other UI dev kit), HTML. When I say replacement, I should also mention corresponding things which are replacing them so here is what I have listed:

  • HTML replaced by Silverlight
  • JavaScript replaced by C#
  • Flash replaced by WPF
silverlight

Silverlight

I am a good ASP.NET programmer and I know C# well. So I can do client side coding in C# instead of JavaScript. Coooooool… That’s good.. Then Flash is replaced by WPF which is nothing but Windows Presentation Foundation which gives Drag and Drop like control in Visual Studio with Rich UI. And the code behind them is again C#. That’s awesome. And HTML is replaced by XAML silverlight which is nothing but a markup language like XML, but the only difference is TAGs are pre-defined unlike XML where we can have anything as TAG name. So I need to just concentrate on C# and XAML. I already know C# now I am left with XAML which is exactly like XML. Let me show you one sample XAML syntax.

<TextBox Name=”txtBox” Text=”Hello Silverlight!”>

</TextBox>

The above XAML code will create a TextBox with “Hello Silverlight!” written in its textbox. It’s so simple. Now I have a technology which is worth learning.

And that’s Silverlight. Now you might have got enough idea on Why Silverlight?

Now we can move to the relationship between WebBrowser, Webserver and Silverlight.

We will try to understand the relationship between web browser, web server and Silverlight.

  1. Web Browser
  2. Web Server
  3. HTTP Protocol

This post is dedicated to these.

1. Web Browser

Web browser is nothing but an application residing on the Operating system which will render the HTML.
Rendering means that it will know how to present the HTML Tags. It’s very important to know about working of web browser and most of the content here will talk about web browser and web server.

I will explain with one example.
When you type http://www.dhaneel.com, you see my blog, but what is happening behind is what I am going to explain.

What web browser does the same thing we are going to do to it with telnet command.

  1. When you type http://www.dhaneel.com -> what is happening is it’s connecting to web server on remote host and giving me the page back.
    Please note that web browser by default connects to port number 80.

    Now open command prompt. You can do that by going to Start -> Run and type the following:

    telnet www.dhaneeel.com 80

[ Note : Telnet Comes along with Windows. It’s a program which can be used to connect to any machine on any port. Like you want to connect to SMTP server of Google. Then use this command.telnet smtp.gmail.com 25]

Figure 1.0 shows usage of telnet to connect to webserver [ Port 80 – Default ].

Figure 1

Once you are connected to the webserver, then you need to talk to the webserver in a language which it can understand and those are called protocols. Webserver supports mainly two protocols:

  1. GET
  2. POST

Get

GET protocol is generally used to request for a page and POST protocol is used to post the data to the webserver. We will discuss the GET protocol.

What webserver expects is a string named GET followed by the page it want to fetch.

GET “page url”

So after connecting to webserver, you need to enter the following thing:

GET http://www.dhaneel.com/msbuild-for-silverlight/

And mainly press Enter twice. That’s how the protocol is designed. That’s it. Now you will have the HTML code coming back from the server.

Figure 2

If you save all this data in a file with .html extension and open it in browser, you will see the same content which you will see when you visit http://www.dhaneel.com/msbuild-for-silverlight/.

The entire HTML comes up to the client side as a DOM document needs to be replaced each time a new request goes to the server. Let me give one example. Suppose you want to delete one mail in your inbox. Then one new request will be sending it to the server and then the entire response HTML without that deleted mail should come back. Then we need to refresh the entire screen.

Then the new concept was added and that was AJAX (Asynchronous JavaScript + XML). You can read more on it here. This gave us the feature for modifying the DOM which was available at the Browser. So each time you delete a mail, an asynchronous request goes to the server and returns back with a flag and based on that, we change the DOM. This new feature which was implemented in the DOM was called Inner HTML property. This allowed us to make use of AJAX kind of calls.

Hope now we are clear with Web Browser and Web Server. Let’s move ahead and find out how Silverlight is working.

For Silverlight, Microsoft has developed a Plug-In which can be called as Light .NET CLR. This can be installed on the browser (currently it can be installed on Internet Explorer, Firefox, Chrome). The Plug-in is nothing but a stripped of version of the FAT .NET CLR.
You can use this to program in C#. You can make use of almost all basic data types which are present in .NET CLR.

Points of Interest

Microsoft is trying to put some lightweight CLR on the client side. I think it's kind of desktop application, but we are making use of web browser to put the necessary components in it.

History

  • 26th May, 2009: Initial post

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here