Link to home
Start Free TrialLog in
Avatar of milani_lucie
milani_lucieFlag for United States of America

asked on

Session Management Using WCF - Silverlight

Hi,

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

=============================================================================

Imports System.ServiceModel

<ServiceContract(Namespace:="")>
Public Interface IService1

    <OperationContract()>
    Sub SetSessionVariable(ByVal SessionKey As String, ByVal SessionValue As String)

    <OperationContract()>
    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.

Thanks

ASKER CERTIFIED SOLUTION
Avatar of jagrut_patel
jagrut_patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial