Пример #1
0
        /// <summary>
        /// Creates a new instance of a service host.
        /// </summary>
        public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses)
        {
            // load the configuration.
            SampleConfiguration configuration = SampleConfiguration.Load("Opc.Ua.Server", ApplicationType.Server);

            // create the object that implements the server.
            SampleServer server = new SampleServer();

            // return the default host.
            return(server.Start(configuration, baseAddresses));
        }
Пример #2
0
        /// <summary>
        /// Creates a new instance of a service host.
        /// </summary>
	    public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses)
	    {
            // load the configuration.
            SampleConfiguration configuration = SampleConfiguration.Load("Opc.Ua.Server", ApplicationType.Server);

            // create the object that implements the server.
            SampleServer server = new SampleServer();

            // return the default host.
            return server.Start(configuration, baseAddresses);
        }
        public void Start()
        {

            try
            {
                Task t = ConsoleSampleServer();
                t.Wait();
                Console.WriteLine("Server started. Press any key to exit...");
            }
            catch (Exception ex)
            {
                Utils.Trace("ServiceResultException:" + ex.Message);
                Console.WriteLine("Exception: {0}", ex.Message);
            }

            try
            {
                Console.ReadKey(true);
            }
            catch
            {
                // wait forever if there is no console
                Thread.Sleep(Timeout.Infinite);
            }

            if (server != null)
            {
                Console.WriteLine("Server stopped. Waiting for exit...");

                server.Dispose();
                server = null;

                status.Wait();
            }
        }
        private async Task ConsoleSampleServer()
        {
            ApplicationInstance.MessageDlg = new ApplicationMessageDlg();
            ApplicationInstance application = new ApplicationInstance();

            application.ApplicationName = "UA Core Sample Server";
            application.ApplicationType = ApplicationType.Server;
            application.ConfigSectionName = "Opc.Ua.SampleServer";

            // load the application configuration.
            ApplicationConfiguration config = await application.LoadApplicationConfiguration(false);

            // check the application certificate.
            bool haveAppCertificate = await application.CheckApplicationInstanceCertificate(false, 0);
            if (!haveAppCertificate)
            {
                throw new Exception("Application instance certificate invalid!");
            }

            if (!config.SecurityConfiguration.AutoAcceptUntrustedCertificates)
            {
                config.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
            }

            // start the server.
            server = new SampleServer();
            await application.Start(server);

            // start the status thread
            status = Task.Run(new Action(StatusThread));

            // print notification on session events
            server.CurrentInstance.SessionManager.SessionActivated += EventStatus;
            server.CurrentInstance.SessionManager.SessionClosing += EventStatus;
            server.CurrentInstance.SessionManager.SessionCreated += EventStatus;

        }