• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 610
  • Last Modified:

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

0
milani_lucie
Asked:
milani_lucie
2 Solutions
 
jagrut_patelCommented:
You should be using a binding that support sessions, and enable PerSession service instances.
0
 
CodeCruiserCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now