Opc.Ua.Client.Session.Create C# (CSharp) Méthode

Create() public static méthode

Creates a new communication session with a server by invoking the CreateSession service
public static Create ( ApplicationConfiguration configuration, ConfiguredEndpoint endpoint, bool updateBeforeConnect, string sessionName, uint sessionTimeout, IUserIdentity identity, IList preferredLocales ) : Session
configuration ApplicationConfiguration The configuration for the client application.
endpoint ConfiguredEndpoint The endpoint for the server.
updateBeforeConnect bool If set to true the discovery endpoint is used to update the endpoint description before connecting.
sessionName string The name to assign to the session.
sessionTimeout uint The timeout period for the session.
identity IUserIdentity The identity.
preferredLocales IList The user identity to associate with the session.
Résultat Session
        public static Session Create(
            ApplicationConfiguration configuration,
            ConfiguredEndpoint endpoint,
            bool updateBeforeConnect,
            string sessionName,
            uint sessionTimeout,
            IUserIdentity identity,
            IList<string> preferredLocales)
        {
            return Create(configuration, endpoint, updateBeforeConnect, false, sessionName, sessionTimeout, identity, preferredLocales);
        }

Same methods

Session::Create ( ApplicationConfiguration configuration, ConfiguredEndpoint endpoint, bool updateBeforeConnect, bool checkDomain, string sessionName, uint sessionTimeout, IUserIdentity identity, IList preferredLocales ) : Session

Usage Example

        private static async Task RunClient(string address)
        {
            var clientApp = new ApplicationInstance
            {
                ApplicationName   = "OPC UA StackOverflow Example Client",
                ApplicationType   = ApplicationType.Client,
                ConfigSectionName = "Opc.Client"
            };

            // load the application configuration.
            var clientConfig = await clientApp.LoadApplicationConfiguration(true);

            var haveClientAppCertificate = await clientApp.CheckApplicationInstanceCertificate(true, 0);

            if (!haveClientAppCertificate)
            {
                throw new Exception("Application instance certificate invalid!");
            }
            var endpointConfiguration = EndpointConfiguration.Create(clientConfig);
            var selectedEndpoint      = CoreClientUtils.SelectEndpoint(address, true, 15000);
            var endpoint = new ConfiguredEndpoint(null, selectedEndpoint, endpointConfiguration);

            using (var session = await Session.Create(clientConfig, endpoint, false, clientConfig.ApplicationName, 60000, new UserIdentity(new AnonymousIdentityToken()), null))
            {
                Console.WriteLine("Client connected");
                var rootFolders = await session.BrowseAsync(ObjectIds.ObjectsFolder);

                Console.WriteLine("Received root folders");
                var childFolders = await Task.WhenAll(
                    from root in rootFolders
                    select session.BrowseAsync(ExpandedNodeId.ToNodeId(root.NodeId, session.NamespaceUris)));

                foreach (var childFolder in childFolders.SelectMany(x => x).OrderBy(c => c.BrowseName.Name))
                {
                    Console.WriteLine(childFolder.BrowseName.Name);
                }
                Console.WriteLine("Client disconnecting");
                session.Close();
                Console.WriteLine("Client disconnected");
            }
            Console.WriteLine("Client disposed");
        }
All Usage Examples Of Opc.Ua.Client.Session::Create