DBIZ Home CRM & ERP Suite If you have a question, contact us Contact Us |   About Us About Us

SilverLight 4.0 Deployment

How to improve efficency of your Silverlight application
PreRequisite: Visual Studio 2010


XAP file and DLLs


Reducing the size of your XAP file is a good idea as it may contain DLLs (and other resources) that have already been downloaded previously and are contained in the browser assembly cache. Bandwidth is a precious thing and you don't want to waste it !

For this article we will use our DBiz ECommerce Open Source application as an example (to get the source code go to http://sourceforge.net/projects/dbiz

  1. Right click on the "ShopCart" Silverlight project and go to Properties.
  2. In the Silverlight tab, go to "Silverlight build options" section and tick "Reduce XAP size by using application library caching".
  3. Rebuild your application and you will notice that the XAP file size has reduced and there are additional ZIP files in the ClientBin directory.
  4. Obviously now you have additional files to deploy on the server (as oppposed to a single XAP file), but the positives far outway the negatives.

How easy was that! Is it too good to be true? Well, almost,  there are additional steps to take when caching your own libraries:

If you have many Silverlight applications, generic code and generic controls you will want to generate a DLL resource. This is the case for the DBIZ ECommerce solution which contains the DBizControls project as well as the ShopCart project. The DBizControls project outputs a DLL which is referenced by the ShopCart Application.

You will notice that the DBizControls.dll file remained in the ShopCart XAP package (you can peak inside the package as a XAP file is the same as a ZIP file with a different extension, so just use your favorite ZIP viewer and you will see the contents).

The reason is that a Library must first be signed to support caching:

  1. Right click on DBizControls project and go to Properties.
  2. In the "Signing" tab, select the "Sign the assembly" tickbox.
  3. Choose "<New...>" for the "strong name key file".
  4. Assign the name "DBizControlKey.snk" and untick "Protect my key file with a password".
  5. Click "Ok".
  6. Rebuild the project.

Next, you must create a map file for use in the External Part manifest of the main application (ShopCart):

  1. Before you can create such a file you must determine the "Public Key Token" of the newly created "strong name key" file. At the command line type:

    sn.exe -p DBizControlKey.snk DBizControlKey.bin
    sn -t DBizControlKey.bin

  2. Copy the output value of the token which will be used in the next section.
  3. Create a plain text file called "DBizControls.extmap.xml" and give it the following content:

    <?xml version="1.0"?>
    <manifest
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <assembly>
    <name>DBizControls</name>
    <version>1.0.0.0</version>
    <publickeytoken>ac2f4aaa7cbcc558</publickeytoken>
    <relpath>DBizControls.dll</relpath>
    <extension downloadUri="DBizControls.zip" />
    </assembly>
    </manifest>

    Please Note: remember to change the value of the "publickeytoken" element with your value.

  4. Add the file to the DBizContols project and give it the following properties:

    "Build Action"=None
    "Copy to Output Directory"=Always
  5. Rebuild the "ShopCart" Project and voila!
IMAGES

Images can make XAP files very large. An alternative is to load images on demand. Here is some code to enable image loading on demand:



Note that the WebClient does not support concurrent IO operations, therefore you must load  each image on a seperate WebClient object each time (this code is from our Tools4Wives project).

SEPARATING CONTENT AND DATA

Bandwidth must be considered when developing Silverlight internet apps. Files can get very large with Silverlight, and if servers are busy delivering dynamic data and large static content from the same site, user wait times can increase. A solution is to serve content and data from 2 different sites, of course this presents the challenge of cross domain support (see DBiz OpenSource Project for ways to deal with cross domain situations).
At GMG Software we have tackled this issue by dedicating servers at our HQ to serving dynamic content, that is the XML Web Services; the DLLs and XAP files are delivered from another site.

Loadin XAP Files Dynamically

Off the MEF method: A Smaller XAP Preloader for Silverlight MEF Xap Loading MEF Xap Loading Video MEF Xap Partitioning MEF Silverlight 4 Toolkit MEF again MEF Community Site MEF Overview