Пример #1
0
        public bool CreateChannel(string specName, bool useSingleton = false)
        {
            string FullName  = this.GetType().Name;
            string ClassName = FullName.Split('\'')[0];
            //if (specName != null)
            //{
            //    ClassName = specName;
            //}
            string ChannelName = string.Format("IPC_{0}", specName);
            string cname       = string.Format("{0}_{1}", specName, ClassName);

            //if (ClassName != null)
            //    ChannelName = ClassName;
            try
            {
                ToLog("IPC服务端日志", "检查是否是管理员", WinComminuteClass.IsRoot().ToString());
                ToLog("IPC服务端日志", "正在初始化通道", ChannelName);
                if (!channels.ContainsKey(ChannelName))
                {
                    ToLog("IPC服务端日志", "注册通道", ChannelName);
                    Hashtable ht = new Hashtable();
                    ht["portName"]        = ChannelName;
                    ht["name"]            = "ipc";
                    ht["authorizedGroup"] = "everyone";

                    BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
                    serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                    BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
                    //IDictionary props = new Hashtable();
                    //props["port"] = Convert.ToInt32(txtClientPort.Text);
                    //HttpChannel chan = new HttpChannel(props, clientProv, serverProv);
                    //CommonSecurityDescriptor csd = new CommonSecurityDescriptor();
                    IpcServerChannel channel = new IpcServerChannel(ht, serverProv);
                    //IpcServerChannel channel = new IpcServerChannel(ChannelName);
                    ChannelServices.RegisterChannel(channel, false);
                    //ToLog("IPC服务端日志", "正在注册通道绑定数据类型", ClassName);
                    ToLog("IPC服务端日志", "注册通道完毕", channel.ChannelName);
                    channels.Add(ChannelName, channel);
                    WellKnownObjectMode mode = useSingleton ? WellKnownObjectMode.Singleton : WellKnownObjectMode.SingleCall;
                    RemotingConfiguration.RegisterWellKnownServiceType(this.GetType(), ClassName, mode);
                    ToLog("IPC服务端日志", "绑定数据类型完毕", ClassName);
                }

                ToLog("IPC服务端日志", string.Format("初始化通道成功"), WinComminuteClass.getAllChannelsInfo());
                //IpcServerChannel channel = new IpcServerChannel(string.Format("WolfIPC_Channel"));
                //RemoteCommClass<T> obj = new RemoteCommClass<T>();
            }
            catch (Exception e)
            {
                ToLog("IPC服务端日志", string.Format("初始化通道[{0},{1}]失败", specName, FullName), e.Message);
                return(false);
            }
            return(true);
        }