Android 无法使用会话 ID 从 Web 服务检索数据

Android can't retrieve data from web service using session ID

我是 android 编程的初学者。我已经启动了一个测试项目,该项目是关于使用 android 应用程序访问 Web 服务和那里的 运行 功能。我正在使用 ksoap2 调用网络服务。

当我想通过 phone 和 Web 服务登录数据库时 return 一个会话 ID 给我。但在那之后,当我想 运行 服务中的其他功能时,我在会话 ID 中传递它,它告诉我有一个空对象引用。我尝试再次使用会话 ID 取回登录详细信息,但它显示该会话未指向任何会话。这是允许我连接 Web 服务的方法。而对于 android,我只是简单地使用 ksoap2 进行调用。

 <WebMethod(True)> _
Public Function CompanyConnectionString() As String

    Dim lErrCode, lRetCode As Long
    Dim sErrMsg As String = ""


    Dim sSessionID As String = ""
    Dim oCompany As SAPbobsCOM.Company
    oCompany = New SAPbobsCOM.Company


//  User and other details to connect
    oCompany.Server = "xx.x.x.xx"    //ip address
    oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012
    oCompany.DbUserName = "dbUser"
    oCompany.DbPassword = "dbPassword"
    oCompany.CompanyDB = "CompanyDB"
    oCompany.UserName = "User"
    oCompany.Password = "Password"
    oCompany.LicenseServer = "xx.x.x.xx:xxxxx"  // ip


    lRetCode = oCompany.Connect


    If lRetCode <> 0 Then
        oCompany.GetLastError(lErrCode, sErrMsg)
        sSessionID = lErrCode & "-" & sErrMsg

    Else
        sSessionID = Session.SessionID.ToString
        Session.Add(sSessionID, oCompany)
        ''
        Cookies.SetCookies(oCompany, "SID")


    End If

    Return sSessionID

End Function

我发现它可能会丢失会话ID,并且我以后无法取回其他功能的登录详细信息。那有什么想法吗?我要怎么办?没有这个我就无法继续我的程序。

提前致谢..

嗯,问题刚刚解决。我和我的朋友发现那是因为 max-age=0; 忘记了 sessionID。所以我们将其添加到我们的 sessionID 中,它 运行.

if (headerKey != null) {
    if (headerKey.equals("Set-Cookie")) {
        cookieBuilder.append(headerValue + "max-age=86400;");
    }
} //headervalue is the sessionID

这将使会话保持活动状态 86400 秒 = 1 天。 因此 sessionID 可用于 运行 Web 服务上的其他功能