Opc.Ua.ServerTest.ServerTestClient.CreateSession C# (CSharp) Method

CreateSession() private method

Creates a session.
private CreateSession ( ApplicationConfiguration configuration, BindingFactory bindingFactory, ConfiguredEndpoint endpoint, IUserIdentity identity ) : Session
configuration ApplicationConfiguration
bindingFactory BindingFactory
endpoint ConfiguredEndpoint
identity IUserIdentity
return Opc.Ua.Client.Session
        private Session CreateSession(
            ApplicationConfiguration configuration, 
            BindingFactory           bindingFactory,
            ConfiguredEndpoint       endpoint,
            IUserIdentity            identity)
        {
            Report("Creating new Session with URL = {0}", endpoint.EndpointUrl);

            // Initialize the channel which will be created with the server.
            ITransportChannel channel = SessionChannel.Create(
                configuration,
                endpoint.Description,
                endpoint.Configuration,
                configuration.SecurityConfiguration.ApplicationCertificate.Find(true),
                configuration.CreateMessageContext());

            // Wrap the channel with the session object.
            Session session = new Session(channel, configuration, endpoint, null);
            session.ReturnDiagnostics = DiagnosticsMasks.All;
            
            // register keep alive callback.
            session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive);
            
            // create the user identity.            
            if (identity == null)
            {
                if (endpoint.Description.UserIdentityTokens.Count > 0)
                {
                    identity = CreateUserIdentity(endpoint.Description.UserIdentityTokens[0]);
                }
            }

            // Create the session. This actually connects to the server.
            session.Open(Guid.NewGuid().ToString(), identity);

            Report("Successfully created new Session.");

            // return the session.
            return session;
        }