Michael Wolf
{Binding ME}
Tuesday July 21, 2009
Silverlight Out of Browser deep dive
Continuing on the Silverlight 3 new feature series, one of the features that has gotten the biggest buzz in the press but the biggest confusion in the development community has been Out of Browser. This entry is to try and clear up the confusion and discuss the option in more detail. Out of Browser is often confused for an "offline" application, however an out of browser application is a Silverlight application which has been enabled to run outside of your browser on windows and mac using its own container regardless of connectivity.
See an update of the notes application from the sample data application, now set up as an out of browser silverlight application. Click on the install button below which is the silverlight application.
Tim Heuer has a great video on silverlight.net showing how its accomplished from a development api experience. I highly recommend those looking for a "how to" look at this video. At its core any Silverlight application which does not have dependencies on the html DOM can be run out of browser. I say with out dependencies on the DOM because as mentioned above, you are not in a browser and thus do not have access to html and java script which was part of your web application. In addition to the lack of the html DOM microsoft has added a new network stack to support out of browser. As that silverlight in browser depends on the browsers networking stack, in out of browser they have added their own w/ some subtle changes to policy files needed etc (more details expected to be provided to the community on this).
Overall think of out of browser Silverlight like as a VERY secure "click once" deployment, that is also cross platform. Of course it is not a "Click Once" but the partial trust environment you must work in developing a click once application is similar , however at the end of the day an out of browser Silverlight application is still sandboxed in the exact same ways as a standard Silverlight or html application is. Which of course is pretty tight.
Out of browser versus offline
Very often developers confuse "Out of Browser" with offline. In reality any Silverlight application can now be fully connection aware. In the pre SL 3 days, if we needed to know if the application was online, we would create a dispatcher timer that would on a schedule "phone home" to a url we know will be up. If the url is hit and responds with an "OK", then we are connected. In SL 3 we now have a feature of the full CLR that lets us catch an event when the connection status changes.
In any Silverlight application you can catch this event to then start saving data to isolated storage, and then when the network is available again post the data to your web services. In addition you might want to set up a dependency property which will be set back and forth on network change to not only save data , but also outright disable certain functionality when not online. This approach goes for in and out of browser experiences.
Installation Experience
One of the more interesting situations with out of browser silverlight is the install experience. First as opposed to Adobe AIR, users do not need to download anything outside of silverlight to run an out of browser experience. In addition the in browser experience is using the same player and runtime as the out of browser experience. That means that the in browser experience can install the out of browser experience. This can either be through development and design choices to prompt a user to install or via the built in context menu.The demo above takes the design/development prompt idea. The button itself is actually the Silverlight application. In our case instead of showing the main notes app with an install button, we decided to just show the install button and disable it after install. What is happening here is there is a grid which has its visibility bound to a dependency property which knows the install and out of browser states.
Then to ensure that the user does not attempt to install the application again, we can bind the IsEnabled state of the button to the InstallState. Overall this method gives you allot of control over the experience of an installer all via silverlight.
The other route is the one taken by the great application Sobees which is now sharing a new Silverlight app w/ offline ability. They are using the out of the box option when "Out of Browser" is enabled in the manifest. Go to their site and right click to install to try it out. Of course there is a hybrid approach, where your on line Silverlight application contains an on line experience with certain features, and an install button for an offline companion app. The offline companion experience might contain other features and experience to complement the on line experience.
Storing data
One of the first things people ask about when they see Silverlight out of browser is "OK, so if I'm on the desktop, can I access a datastore?". The answer is yes and no. First off it should be noted you can still call the same web services you can in your in browser experience, however when running out of browser you likely want to also run offline/somewhat connected. Thus in out of browser Silverlight you get 25 mb of isolated storage. This can be increased using a user interaction, but out of the box you get 25 mb. With that isolated storage you can then serialize your data to xml to store and query off of using linq. In the example above, we simply serialize the model objects, and store them and reload them to and from isolated storage when the application is out of browser.
This functionality can be developed with out of the box functionality and could be built up to become more of an object oriented data structure. However there are some people working on bring a full fledged OO database to Silverlight. The 2 most promising currently seem to be the following.
- http://silverdb.codeplex.com/ : this is a fairly new project but shows promise.
- db4o: this is a more mature project which seems to be getting close to a Silverlight port.
- Perst: looks to be a great option as well, and ready to go today
It should be noted also that you can not access the file system silently in Out of Browser. This means that currently you can not write a file to the file system with out showing a save dialogue. Thus this limits other options of text file based data sources.
How does it compare to Adobe Air
First thing to note, Out of Browser Silverlight != Adobe Air. On principle they are technologies designed to bridge the web to desktop experiences using the same skills and platform, but the 2 products take distinctly different approaches. Adobe AIR applications run in full trust on the desktop machine, thus the only limitations which are placed on the developer as far as OS interaction are based on the lack of AIR api development, not a security restriction. On the other hand Out of Browser silverlight is restricted by a strict sandbox by design, thus many of the differences lie there in. In addition AIR is a separate runtime from the Flash Player, where as Silverlight Out of Browser is utilizing the same runtime, only contained with an OS specific container. The stage being set, below is a list of functionality that either AIR can do that Out of Browser Silverlight can not and vice versa. This is not meant as a complete feature to feature breakdown but a high level look.AIR
- Custom window chrome.
- Toast Notifications
- Write and read silently from the filesystem
- native support for SQL lite
- Drag and Drop OS support
- Deny software updates
Silverlight Out of Browser
- Installation with no other install but the silverlight player
- Installer integrated into running ria, to support deployment and web use from same ui
- Single project file
It should be noted neither technology currently includes full access to the OS. You can however break the sandbox in either AIR or Out of browser using socket services. See my blog post here to see it in action using Silverlight.
Why use it?
This really comes down to are you developing a true desktop application or a companion desktop experience to a web based RIA. If you are building a desktop experience that can exist only on windows, WPF is your best bet. If your reason to shy from WPF is deployment , look at Click Once deployments. More often than not a click once deployment will get you the desktop experience your looking for, with the lack of IT interactions your looking for in a web based RIA. However if you are looking to bridge a cross platform companion desktop experience with little separation from a deployment (extra download) , and development base line perspective Out of Browser is a great option. If you truly need a cross platform solution but with less sandbox restrictions, AIR would be your best bet. It's all about the right tools for the right situations, and Out of Browser has definitely staked its claim in this ecosystem.






