Silverlight controls are client side controls. They get executed on the browser on the client machines and they do not have direct access to the server side data.
Since Session variables live on the web server, Silverlight controls cannot access them directly. However, there are several ways Silverlight can retrieve the server side data including Session information.
Let us explore some of the possible options to make Session data available to Silverlight controls.
Option 1: Push session data to the client in the form of VIEWSTATE data or data for UI controls. The dis advantage with this approach are no type safety, only minimal data can be sent, data is visible to users etc.
Option 2: Use the InitParameters property of the Silverlight controls to push data to the Silverlight controls. This approach also have problems like no type safety, only minimal data can be sent etc.
Option 3: Use WCF service calls to retrieve data from server. Using this approach, Silverlight controls can call WCF services to retrieve larger volume of data without having the disadvantages of the above 2 options.
To use WCF to get Session data from server to Silverlight controls, all you need to do is create a simple WCF service. This service should have a method that takes the session key as input parameter and return the corresponding value from the session, as shown below:
public object GetSessionVariable(string key)
Continue reading the next part of this chapter