?
Solved

Session Management Using WCF - Silverlight

Posted on 2011-10-02
2
Medium Priority
?
597 Views
Last Modified: 2012-06-27
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
Comment
Question by:milani_lucie
2 Comments
 
LVL 8

Accepted Solution

by:
jagrut_patel earned 1000 total points
ID: 36901682
You should be using a binding that support sessions, and enable PerSession service instances.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 1000 total points
ID: 36902413
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question