在asmx应用程序中获取唯一会话

时间:2014-07-14 11:37:44

标签: .net vb.net web-services session asmx

我有一个网络服务asmx,我有这些方法

 <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

我的问题是当我调用Debug.Print(Session.SessionID)时,我收到错误表示Session对象没有实例化。所以我需要知道

  • 如何在所有方法调用期间维护唯一的会话ID?
  • 即使我使用相同的winforms应用程序作为使用此服务的客户端应用程序,更改会话的原因是什么?

1 个答案:

答案 0 :(得分:1)

您需要传递从客户端创建的会话ID,这将存储在服务器端。在进行另一次通话时,您将检查会话是否已存在......