简体   繁体   中英

Datasnap session has expired

I've been using client server application using datasnap... Everything works flawlessly until server is restarted. Once server is restarted client has to be restarted as well. If do not restart client, client can't communicate with server because of annoying issue "session has expired". Who faces same issue? How to solver? Thanks

I've created example project to clarify what I mean. Download link

Steps to reproduce the issue:

  1. Open ProjectGroup1.groupproj
  2. Compile and run rest project. It's server
  3. Compile and run client project.
  4. Click start button on rest project
  5. Click button1 on client project. It will call rest EchoString method
  6. Click stop button on rest project
  7. Click start button on rest project
  8. Click on button1 on client project. You have to get "Session has expired" issue

Ok, It seems I found a solution.

On client side just set TDSRestConnection.PreserveSessionID=False. I suppose every request will have new session id, thus it will never expire...

TDSRestConnection.PreserveSessionID=False

It is an easy way to create a new session each time, but it can put unnecessary stress on the server.

When a session timeout occurs, it is better to initialize the session with the code below and request again.

TDSRestConnection.SessionID := '';

Handling the client like this and properly adjusting the server's session timeout time can make the server more effective.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM