Search code examples
.netvb.netweb-servicessessionasmx

Getting a unique session within asmx application


I have a web service asmx in which I have these methods

 <WebMethod()>
    Public Function VerifyCalcAlgoFinish() As Boolean
        Try
            Debug.Print(Session.SessionID)
            Return Session("session_variable") = True
        Catch ex As Exception
            Return False
        End Try
    End Function

<WebMethod(EnableSession:=True)> _
    Public Function Calc() As boolean

        If Session("session_variable") Is Nothing Then
            Session("session_variable") = false
        End If
        Try
           // some instructions
            Session("session_variable") = true
        Catch ex As Exception
            Session("session_variable") = false
        End Try

        Return Session("session_variable")

    End Function

My problem is when i called Debug.Print(Session.SessionID) i get an error indicates that the Session object is not instanciated. So I need to know

  • How can i maintain a unique session id during all methods calls?
  • What is the reason of changing the session even i'm using the same winforms application as a client application consuming this service?

Solution

  • You would need to pass the session ID created from the client, and this would be stored server side. When doing another call, you would then check if the session already exists...