Sessions sample (.NET)

Overview

This sample demonstrates the Session Management: How to create and work with server session variables on the client side using Remoting SDK components.

Getting Started

Build and launch the Sessions Sample server. The server will be activated automatically. Build and launch the Session Sample client. Set the User ID and Password properties to login. Please note that the User ID should be the same as the Password to login successfully. After login, the corresponding Client's GUID will be shown at the bottom of the client form. The server will log information about the client. Set the session item properties Name and Value and click the button Set Value.The corresponding session variable will be stored on the server side. To get the session variable value, click Get Value.

Examine the code

Server side

The Sessions Sample server represents the Remoting SDK server with the MemorySessionManager component that allows you to work with sessions and a service that gets and sets the session variable using the service's Session object.

//private RemObjects.SDK.Server.MemorySessionManager memorySessionManager;
public virtual string GetSessionValue(string Name) 
{
   return (string)Session[Name];
}

public virtual void SetSessionValue(string Name, string Value) 
{
   Session[Name] = Value;
}

Client side

The Sessions Sample client represents the Remoting SDK client with the service proxy objects ILoginService and ISessionService. The client uses standard service calls to login/logout and get/set session variables:

private ISessionService sessionService = null;
private ILoginService loginService = null;
private bool loggedIn = false;

private void Form1_Load(object sender, System.EventArgs e)
{
   loginService = CoLoginService.Create(message, clientChannel);
   sessionService = CoSessionService.Create(message, clientChannel);
   . . .
}

private void bLogin_Click(object sender, System.EventArgs e)
{
   loggedIn = loginService.Login(tbUserID.Text, tbPassword.Text);

   if (!loggedIn) 
   {
      . . .
   }
}

private void bLogout_Click(object sender, System.EventArgs e)
{
   loginService.Logout(message.ClientID.ToString());
   . . .
}

private void bSetValue_Click(object sender, System.EventArgs e)
{
   sessionService.SetSessionValue(tbItemName.Text, tbItemValue.Text);
}

private void bGetValue_Click(object sender, System.EventArgs e)
{
   tbItemValue.Text = sessionService.GetSessionValue(tbItemName.Text);
}