我是Visual Basic的新手,我在尝试创建一个负责确保Web服务代理会话仍然有效的类时遇到了一些麻烦。为了做到这一点,需要调用几个方法,所以我试图弄清楚如何将所有这些方法嵌套到一个函数中,然后在继续执行另一个方法之前返回代理对象。这是我正在尝试做的一个伪示例
Public Shared Function CheckSession(ByVal cookie As String) As ServiceProxy
'first check if cookie is still valid calling one service method
Sub CheckCookie()
Dim ap As AuthenticationProxy = New AuthenticationProxy
AddHandler ap.CheckCookieCompleted, AddressOf CheckCookieCallback
ap.CheckCookieAsync(cookie)
End Sub
Sub CheckCookieCallback(ByVal sender as Object, ByVal e As CheckCookieCompletedEventArgs)
Dim result as Boolean = e.Results.status
'from here based on session status I will either finish the function or move on to another method for getting a new cookie from the server
'at the end of the function I will have the proxy class used by other methods
End Function
那么我想要做的就是当我真的想要使用ServiceProxy时我会首先调用这个函数,如下所示(cookie字符串存储在IsolatedStorage中,但为了简单起见,我不包括所有这只是一个简单的例子):
Public Sub VerifyCredentials(ByVal name as String, ByVal pass as String)
Dim proxy as ServiceProxy = CheckSession(cookie)
'''...