Show TOC

Background documentationSession Mangagement Locate this document in the navigation structure

 

The next class encapsulates everything needed for session management (client & server). The application needs to provide the .NET Connector with an object of type ISessionManager, which then creates (or returns an existing) session ID, whenever the .NET Connector needs one. Session IDs are required for stateful RFC communication in both, client and server scenarios.

public class RfcSessionManager

public static ISessionProvider SessionProvider

This property can be set by the application at most once. If not set, no stateful communication is possible, neither in client nor in server scenarios. Applications that don’t need their own sophisticated session management, but still want stateful communication, can register an object of type RfcSessionProvider. See below.

public static void BeginContext(RfcDestination destination)

This starts a stateful call sequence for RFC client programs. The RfcSessionManager first asks the ISessionProvider object for the session ID corresponding to the current thread of execution. Then it checks, whether there is already a physical connection from the given destination’s connection pool reserved for this session ID. If not, the RfcSessionManager takes a connection from the pool and reserves it for the exclusive usage by the current session/execution thread. If there is already one reserved for the current session ID, a corresponding “reference counter” is incremented. This allows re-entrant client sessions.

public static void EndContext(RfcDestination destination)

Ends a stateful call sequence for RFC client programs. Again the session ID belonging to the current thread is obtained and then the reference counter for the exclusively reserved RFC connection is decremented. Once the reference counter reaches 0, the connection is returned to the given destination’s connection pool. The application can implement the following interface, if it needs to provide more sophisticated session management in application server environments.

public interface ISessionProvider

public String GetCurrentSession()

Returns the session ID associated with the current thread of execution. Used mainly by the RfcSessionManager in RFC client scenarios.

public String CreateSession()

Asks the application environment to create a new user session and attach the current thread with the new user session. Used by the .NET Connector in RFC server scenarios, when the SAP backend system opens a new connection to the external server program.

Note Note

This is partly related to IServerSecurityHandler. However, we decided to keep the two notions of “session management” on one side and “user logon check” on the other side separated from each other, so that those applications that are not interested in session management and stateful communication, can still protect their server application by logon and user validation mechanisms.

End of the note.

public void PassivateSession(String sessionID)

The .NET Connector calls this API, whenever an RFC request, which is processed as part of a stateful server connection, has been finished and the corresponding stateful server connection is now idle (waiting for the next RFC request from the backend). The ISessionProvider should detach the given user session from the current thread

public void ActivateSession(String sessionID)

The .NET Connector calls this API, whenever a new RFC request comes in over an already existing stateful server connection. The ISessionProvider should attach the given user session with the current thread.

public void DestroySession(String sessionID)

The .NET Connector calls this API, whenever the SAP backend system (or the implementation of a server function) closes a stateful server connection. The application framework’s session management should now close the corresponding user context.

public bool IsAlive(String sessionID)

Allows the .NET Connector to test, whether a particular application user session is still alive. Application that have no need for a sophisticated user session management, can register the following default implementation of ISessionProvider with the RfcSessionManager. This is a simple implementation using the current thread’s thread ID as session ID.

public class RfcSessionProvider:ISessionProvider