Maintaining Session in Silverlight
This can be very useful when you create a
business application or a simple application wherein you need a login
form. As you all know, Silverlight does not support session, but this
can be implemented with the?help of aspx page, which supports session.
?
How do we implement this;
Simple. Use WCF service; I dont think there is a better option than this.
?
example:
I am creating a Service class, which has two methods GetSessionValues and SetSessionValues; Since I am using .Net framework 4.0, I can?utilize the?Dictionary class to send / receive a set of data to / from the server.
?
Here are the methods used
?
?
How do we implement this;
Simple. Use WCF service; I dont think there is a better option than this.
?
example:
I am creating a Service class, which has two methods GetSessionValues and SetSessionValues; Since I am using .Net framework 4.0, I can?utilize the?Dictionary class to send / receive a set of data to / from the server.
?
Here are the methods used
?
[OperationContract]
public bool SetSessionValues(Dictionary sessionValues)
{
bool isSuccess = false;
try
{
foreach (var item in sessionValues)
{
System.Web.HttpContext.Current.Session[item.Key] = item.Value;
}
isSuccess = true;
}
catch (Exception ex)
{
isSuccess = false;
AppWebHelper.LogError(ex, "SetSessionValues", "SessionManagerService");
}
return isSuccess;
}
[OperationContract]
public Dictionary GetSessionValues(List sessionKeys)
{
Dictionary sessionValues = new Dictionary();
try
{
foreach (string key in sessionKeys)
{
if (System.Web.HttpContext.Current.Session[key] != null)
{
sessionValues.Add(key, Convert.ToString(System.Web.HttpContext.Current.Session[key]));
}
}
}
catch (Exception ex)
{
AppWebHelper.LogError(ex, "GetSessionValues", "SessionManagerService");
}
return sessionValues;
}
Comments
Post a Comment