(X) Hide this
    • Login
    • Join
      • Say No Bots Generate New Image
        By clicking 'Register' you accept the terms of use .

Getting ready for Microsoft Silverlight Exam 70-506 (Part 7)

(10 votes)
Gill Cleeren
>
Gill Cleeren
Joined Apr 02, 2010
Articles:   63
Comments:   6
More Articles
4 comments   /   posted on Feb 25, 2011
Categories:   General
SilverlightShow and Gill Cleeren started a series of materials aimed at helping you get prepared for taking Microsoft Silverlight Exam 70-506. Through this series we tried to structure the resources available on the internet, grouping them by topic covered in the exam. Any feedback would be much appreciated! Thanks! 

This article is Part 7 of the series on Microsoft Silverlight Exam.

We made it! After 7 parts, many topics addressed and much knowledge gathered, we have arrived at the last part of this article series on getting ready for the Silverlight exam. If you followed along, you just have this last part to work through and then you can feel confident about taking the exam.

In this last part, we’ll be addressing topics that are closely related to the deployment of Silverlight applications, something that typically is of high importance at the end of a project. The term deployment can be interpreted quite wide as you’ll see. We’ll start by taking a look at how we can take control over the configuration of the Silverlight plug-in. As you probably know, the Silverlight control is hosted inside an object tag inside your HTML code. We can change parameters here to change the behavior of the Silverlight control. We’ll also take a look at how we can split up our application in multiple files, making the initial download size smaller. We’ll finish off by looking at the concept of a policy file.

For your convenience, the following list contains links to the other parts of the article series which have been finished already:

Part 7: Deploying applications

When we build a small Silverlight application that lives on its own, doesn’t do heavy rendering of animations, doesn’t access a service for getting data or isn’t very big, we will not run into any deployment headaches. The Silverlight application will be a single XAP file that can be deployed to a server (the server doesn’t need ASP.NET or IIS to be running even, it can be any web server such as Apache) as a file copy. We do need to include the Silverlight.js JavaScript file and a hosting HTML (can be *.aspx, *.php…) from where the Silverlight application will be hosted. When a visitor browses to the webpage containing the Silverlight application, the JavaScript file and the XAP file are downloaded and the Silverlight plug-in can now render the application. Things couldn’t be easier.

In real life, things are often a tad more complicated. In many if not all cases when building business applications with Silverlight, we will be accessing services. As we discussed in part 3 of this series, Silverlight is well equipped to access many types of services. However, to access the service if it isn’t in the same domain as where the Silverlight application originated, Silverlight will perform a check on the presence of a policy file. This file is a safety mechanism so that the server can block service requests from client-side browser applications. If we have control over the service, we can create the file ourselves. We’ll see how we can do that.

Next to the policy file, other security measures need to be taken into account. For example, if we want to access a service that’s protected using ASP.NET membership, can we access this service from Silverlight? The answer is yes: because the request to a service is made by the browser and because the browser sends along the cookies with the request, the ASP.NET authentication cookie will travel with a service request that originated in Silverlight as well. This way, we can limit who can access services.

Another issue we may be faced with is growing XAP size. A simple application that doesn’t use many external resources or assemblies, can be downloaded in one go at the startup of the application. But if we start using a lot of external assemblies or large images, the file size of your XAP will quickly increase, making the startup experience for the end-user a lot less pleasant. A solution is assembly caching, which can be compared somehow to building a client-side GAC (Global Assembly Cache). Alternatively, we can split our application in more XAPs, which can be downloaded when needed. Several mechanisms exist to achieve this, including the use of ZIP files or using MEF (Managed Extensibility Framework). We’ll see how we can tackle this problem as well.

Finally, simple applications will be able to use the default OBJECT tag that’s generated with the standard page when creating a new Silverlight application. If we however need more control over how the plug-in is instantiated, such as the size, we can do so. We can for example also configure that the plug-in will display a frame rate counter. We’ll look at the many options we have to do this configuration.

Configure the Silverlight plug-in

When we create a new Silverlight solution, Visual Studio creates a hosting website where both an ASP.NET and an HTML file are generated where we can test our application in. If we take a look at this code, we can see that the Silverlight application is hosted through an OBJECT tag. Because this is normal HTML, the OBJECT tag can have several PARAMS. Probably the most important one is the source param, which refers to the XAP file (by default located in the ClientBin directory).

Using these parameters, we can configure the Silverlight plugin. Quite logically, these parameters have a predefined name. Mostly, these parameters can be used to enable or disable an option such as transparency of the Silverlight plugin. One exception to this is the InitParams parameter. The value of this one is a dictionary-like list of key/value pairs that are passed to the Silverlight application (so in the form param1=value1;param2=value2). These parameters are passed to the Startup method of the App class and are accessible there via the e.InitParams. Note that these parameters are not accessible in any other location, so if you want to capture them, you have to do it there.

Another parameter that requires some extra attention is the windowless mode. Through this parameter, we can define whether or not we want any HTML that lies behind the Silverlight plugin to “shine” through or not.

Take a look at the following links to learn more about the configuration of the plugin.

Dynamically load application resources

As I mentioned in the intro, if your application’s XAP file is small (because it doesn’t include a lot of (third-party) assemblies or resources such as images), your users will have a good experience out-of-the-box. Once the user goes to your application, he’ll see the standard spinning wheel if the download of your XAP takes longer than 500ms. If your application is small, there’s no real need to start dividing it into several, smaller XAPs or extra ZIP files.

Things change when you are using more assemblies. I hope you all know that the Silverlight plugin, when installed on the client machine, install a few assemblies along, including among others System.Net, mscorlib, Sytem.Windows and System.Windows.Browser. These are therefore available on the client system and don’t need to be added to your XAP file when you use them in your app. When you add for example a DataGrid, automatically several new assembly references are added (System.Windows.Controls.Data, System.ComponentModel.DataAnnotations and System.Windows.Controls.Data.Input). These assemblies will be added to your XAP file, therefore enlarging the size of your XAP quite a lot.

The bad news is that this is happening for every application you are building. This means that if a user browses to 10 different applications that all use the DataGrid, these 3 assemblies will be included in each download. This happens because there’s no access to a GAC from Silverlight on the client machine. We can however sort of enable this via the Assembly Caching feature. When we enable this in the properties of our Silverlight project, all referenced assemblies will be included as a ZIP file in the client bin (and not embedded in the XAP file), as you can see in the below image.

The result for the user browsing to 10 applications with the DataGrid is the following:

  • When hitting the first site, the XAP is downloaded as usual (the XAP doesn’t include the assemblies)
  • The application manifest is opened, in this file, all the assemblies that it needs are included as ExtensionParts.
  • Silverlight will look if it can locate these files on the client system. This mimics the behavior of a local assembly cache/GAC.
  • If it can find it, it will use the local version. If not, the assembly will be downloaded as a ZIP file and stored for future use.
  • When the user now browses to another application with the same assembly references, Silverlight will notice that it has the file locally already and use it from there, bringing down the download (and startup) time a lot!

One small note: this works for both system and custom-built assemblies (contrary to what many sites and articles will say. In the beta of Silverlight, this only worked for system assemblies).

Alternatively, we can also create ZIP files ourselves and download the ZIP file on demand. Once downloaded, we can extract this ZIP and use all its contents. This way, we can include assemblies, XAML code (XAML can be loaded in dynamically through the use of the XamlLoader), images, resource dictionaries…

Another option we have to split an assembly into several parts and load on-demand is using MEF.

In the following links, more information about loading resources dynamically can be found.

Create a client access policy

When your application needs data, it needs access to a service. If that service, be it a WCF, ASMX or REST service, is located in the same domain as the Silverlight application, Silverlight will allow the communication to take place without any further configuration needed. If however, the service is hosted in another domain, things are different.

What happens is the following:

  • Silverlight notices you are accessing a service in different domain (example anotherdomain.com )than where it’s hosted.
  • It will check for the existence of a policy file on the root of the domain. This file can be the Silverlight policy file (clientaccesspolicy.xml) or the Flash policy file (crossdomain.xml).
  • If the file is present, Silverlight will check it to see if there’s no domain restriction. Through the policy file, services can limit from which domain they are being accessed. If all this is OK, Silverlight will allow the communication
  • If the file isn’t present or the domain from where the call originates is not allowed, Silverlight will block the service call.

More information on the client access policy files can be found in the following articles and posts.

 

Summary

In this part, we looked at issues we may come across when we are ready to deploy an application. If we need access to services that are hosted in a different domain, we need to use a policy file. If our application becomes too large, we need to look at options to split it in several parts (either using assembly caching or placing resources in a ZIP file which we can download and open on the client). If we need to configure the Silverlight plug-in, we need to take a look at the OBJECT tag in which Silverlight is hosted. Through the use of parameters, we can configure how the plug-in will behave.

 

Global summary

If you have read all the articles on getting ready for the Silverlight exam, you can feel confident about taking the exam. You have now a very profound knowledge about the topic and not only learned for the exam, but also learned a lot about the tool we all love: Silverlight!

About Gill

Gill Cleeren is Microsoft Regional Director (www.theregion.com), Silverlight MVP (former ASP.NET MVP), INETA speaker bureau member and Silverlight Insider. He lives in Belgium where he works as .NET architect at Ordina. Passionate about .NET, he’s always playing with the newest bits. In his role as Regional Director, Gill has given many sessions, webcasts and trainings on new as well as existing technologies, such as Silverlight, ASP.NET and WPF at conferences including TechEd Berlin 2010, TechDays Belgium, DevDays NL, NDC Oslo Norway, SQL Server Saturday Switserland, Spring Conference UK, Silverlight Roadshow in Sweden… He’s also the author of many articles in various developer magazines and for SilverlightShow.net. He organizes the yearly Community Day event in Belgium.

He also leads Visug (www.visug.be), the largest .NET user group in Belgium. Gill recently published his first book: “Silverlight 4 Data and Services Cookbook” (Packt Publishing). You can find his blog at www.snowball.be.

Twitter: @gillcleeren


Subscribe

Comments

  • -_-

    RE: Getting ready for Microsoft Silverlight Exam 70-506 (Part 7)


    posted by Sarah Martin on Mar 09, 2011 09:13
    Exam 70-506 is intended for software developers who are creating rich Internet-based applications using Silverlight. The exam focuses mainly on Silverlight 4, but also covers core Silverlight concepts.Silverlight 4 development course is now simplified by experts of real exams, now using this study material you can get high grades because these are very close to real exam questions & answers.

    URL:
    http://www.realexams.net/microsoft-70-506.htm
  • -_-

    RE: Getting ready for Microsoft Silverlight Exam 70-506 (Part 7)


    posted by Derrick Edword on Mar 19, 2011 08:18
    MICROSOFT 70-506 exam is very important in your future work. MICROSOFT 70-506 Training Tools help you pass your 70-506 Exam in your first attempt. Just download the  MICROSOFT 70-506 Practice Questions & Answers, MICROSOFT 70-506 Practice Testing Software.

    http://70-506.blogspot.com


  • -_-

    RE: Getting ready for Microsoft Silverlight Exam 70-506 (Part 7)


    posted by Sanchai K. on Mar 21, 2011 13:12
    Hi Gill,

        I have passed the exam today with score 960. Your articles help me alot. thank you very much. :)
  • -_-

    RE: Getting ready for Microsoft Silverlight Exam 70-506 (Part 7)


    posted by Gill Cleeren on Mar 21, 2011 14:00
    Great, congratulations!

Add Comment

Login to comment:
  *      *       

From this series