Click here to Skip to main content
15,880,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to use session in Silverlight?
Posted

Hello, session is a server side concept. Silverlight runs on the client, so it has no knowledge of the session. But you can pass some variable from the Silverlight application to the server via a web service. Then in the web service, you store it as a session variable. Later when you call another web service, you can check the session variable and return it to the client.
While WCF also has built-in session support, BasicHttpBinding doesn't support that. So you need to use ASP.NET session instead. To enable ASP.NET session on WCF, you need to turn on ASP.NET Compatibility. Do the following:
In web.config, under system.serviceModel tag, add this line:
<servicehostingenvironment aspnetcompatibilityenabled="true">
On your service class (not interface), add this attribute:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
Now you can use ASP.NET session with the following syntax:
HttpContext.Current.Session["YourName"] = something;
object something = HttpContext.Current.Session["YourName"];
That being said, I think in your scenario, it's better to store your object on the client side using isolated storage or an application level variable.
 
Share this answer
 
v2
Isolated storage can be used to store session information.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900