【发布时间】:2023-04-10 11:03:01
【问题描述】:
我有一个网络服务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) 时,我得到一个错误,表明会话对象没有被实例化。所以我需要知道
- 如何在所有方法调用期间保持唯一的会话 ID?
- 即使我使用与使用此服务的客户端应用程序相同的 winforms 应用程序,更改会话的原因是什么?
【问题讨论】:
-
您需要传递从客户端创建的会话 ID,这将存储在服务器端。在进行另一个呼叫时,您将检查会话是否已经存在...
-
@Mez 如何通过 id 获取会话??
-
当您关闭与服务的连接时,会话将不复存在,除非已存储。您需要将会话存储在您身边,然后将其传递给服务......
-
@Mez 将您的评论作为答案,这对我有用;)谢谢
-
很好,你想通了。
标签: .net vb.net web-services session asmx