Session Management Using WCF - Silverlight


I want to handle Session Management using WCF in Silverlight. Here is the sample code:


Imports System.ServiceModel

Public Interface IService1

    Sub SetSessionVariable(ByVal SessionKey As String, ByVal SessionValue As String)

    Function GetSessionVariable(ByVal SessionKey As String) As String

End Interface


Imports System.ServiceModel.Activation

<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
Public Class Service1
    Implements IService1

    Public Sub SetSessionVariable(ByVal SessionKey As String, ByVal SessionValue As String) Implements IService1.SetSessionVariable
        System.Web.HttpContext.Current.Session(SessionKey) = SessionValue
        System.Web.HttpContext.Current.Session.Timeout = 20
    End Sub

    Public Function GetSessionVariable(ByVal SessionKey As String) As String Implements IService1.GetSessionVariable
        Return System.Web.HttpContext.Current.Session(SessionKey)
    End Function

End Class


Private Sub MainPage_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Dim svc As New ServiceReference1.Service1Client()
        svc.SetSessionVariableAsync("Key", "Hello World !")
End Sub


I am getting "Object reference not set to an instance of an object." at:

System.Web.HttpContext.Current.Session(SessionKey) = SessionValue

Can you please change my code and make it working ? My WCF Service is in .WEB project. I am accessing that by using proxy in Silverlight project.


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You should be using a binding that support sessions, and enable PerSession service instances.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.