public void Stop()
        {
            // 终止 OPC 网关 WebAPI 服务
            try
            {
                _host.Close();
                _host = null;
                Debug.WriteLine("OPC 网关服务关闭");
            }
            finally
            {
                statueOPCService = false;
            }

            // 终止 KepServer 消息侦听
            for (int i = listeners.Count - 1; i >= 0; i--)
            {
                TKepServerListener listener = listeners[i];
                listeners.Remove(listener);

                listener = null;
            }

            // 终止 OPC Value 消息队列处理线程
            TIRAPOPCTagValueQueueOut.Instance.Stop();
        }
        public void Start()
        {
            // 打开 OPC 网关 WebAPI 服务
            try
            {
                _host = new ServiceHost(typeof(OPCGatewayService));
                foreach (ServiceEndpoint sep in _host.Description.Endpoints)
                {
                    sep.Behaviors.Add(new BehaviorAttribute());
                }
                _host.Open();
                statueOPCService = true;
                Debug.WriteLine("OPC 网关服务启动完成");
            }
            catch (Exception error)
            {
                Debug.WriteLine("OPC 网关服务启动失败,原因:[{0}]", error.Message);
            }

            // 加载数据库中已注册的设备列表
            TIRAPOPCDevices.Instance.SetWebAPIParams(
                TOPCGatewayGlobal.Instance.WebAPIParam.BrokeUri,
                TOPCGatewayGlobal.Instance.WebAPIParam.ContentType,
                TOPCGatewayGlobal.Instance.WebAPIParam.ClientID);
            TIRAPOPCDevices.Instance.GetDevices(
                TOPCGatewayGlobal.Instance.SysParams.CommunityID,
                TOPCGatewayGlobal.Instance.SysParams.SysLogID);

            Debug.WriteLine(
                "当前在 IRAP 系统中注册的 OPCDevice 数量[{0}]",
                TIRAPOPCDevices.Instance.Devices.Count);

            // 创建 OPCTag 出队处理线程池
            //TIRAPOPCTagValueQueueOut.Instance.Start();

            // 根据配置文件内容,创建 KepServer 连接
            TIRAPOPCServers.Instance.LoadFromDataFile(TOPCGatewayGlobal.Instance.ConfigurationFile);
            foreach (TIRAPOPCServer server in TIRAPOPCServers.Instance.Servers)
            {
                try
                {
                    TKepwareServers.Instance.Servers.Add(
                        new TKepwareServer(
                            server.Address,
                            server.Name));
                }
                catch (Exception error)
                {
                    Debug.WriteLine(error.Message);
                }


                TKepServerListener listener = new TKepServerListener();
                listener.Init(server.Address, server.Name);
                listeners.Add(listener);
            }
        }