Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        public void Start()
        {
            if (!_isStarted)
            {
                Xdgk.Common.RemoteObject.Executeing += new ExecuteEventHandler(RemoteObject_Executeing);

                IDictionary tcpProperties = new Hashtable();
                tcpProperties["name"] = "RemoteTest";
                tcpProperties["port"] = 9000;

                BinaryClientFormatterSinkProvider tcpClientSinkProvider =
                    new BinaryClientFormatterSinkProvider();

                BinaryServerFormatterSinkProvider tcpServerSinkProvider =
                    new BinaryServerFormatterSinkProvider();

                tcpServerSinkProvider.TypeFilterLevel =
                    System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                TcpChannel tcpChannel = new TcpChannel(
                    tcpProperties,
                    tcpClientSinkProvider,
                    tcpServerSinkProvider);

                ChannelServices.RegisterChannel(tcpChannel, false);

                RemotingConfiguration.RegisterWellKnownServiceType(
                    typeof(Xdgk.Common.RemoteObject),
                    "RO",
                    WellKnownObjectMode.Singleton);

                _isStarted = true;
            }
        }
Esempio n. 2
0
        public bool init_ipc_recv(string recv_id)
        {
            bool result;

            if (null != this.IPCRecv)
            {
                result = true;
            }
            else
            {
                BinaryServerFormatterSinkProvider binaryServerFormatterSinkProvider = new BinaryServerFormatterSinkProvider();
                binaryServerFormatterSinkProvider.TypeFilterLevel = TypeFilterLevel.Full;
                BinaryClientFormatterSinkProvider clientSinkProvider = new BinaryClientFormatterSinkProvider();
                IDictionary dictionary = new Hashtable();
                dictionary["portName"] = recv_id;
                this.chan = new IpcChannel(dictionary, clientSinkProvider, binaryServerFormatterSinkProvider);
                ChannelServices.RegisterChannel(this.chan, false);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(Hello), "remote_obj", WellKnownObjectMode.Singleton);
                this.IPCRecv = (Hello)Activator.GetObject(typeof(Hello), "ipc://" + recv_id + "/remote_obj");
                if (null == this.IPCRecv)
                {
                    Console.WriteLine("IPC recv 无法定位到服务器。");
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            return(result);
        }
        static void Main()
        {
            IDictionary props = new Hashtable();

            props["port"] = 0;  // let the system choose a free port
            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
            TcpChannel chan = new TcpChannel(props, clientProvider, serverProvider);  // instantiate the channel

            ChannelServices.RegisterChannel(chan, false);                             // register the channel

            ChannelDataStore data = (ChannelDataStore)chan.ChannelData;
            int port = new Uri(data.ChannelUris[0]).Port;                                                                            // get the port

            RemotingConfiguration.Configure("Client.exe.config", false);                                                             // register the server objects
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ClientNotify), "ClientNotify", WellKnownObjectMode.Singleton); // register my remote object for service

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormLogin(port)
            {
                FormBorderStyle = FormBorderStyle.FixedSingle
            });
        }
Esempio n. 4
0
        /// <summary>
        /// 开始
        /// </summary>
        public void Start()
        {
            try
            {
                //设置反序列化级别
                BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
                BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
                serverProvider.TypeFilterLevel = TypeFilterLevel.Full;//支持所有类型的反序列化,级别很高

                //注册信道
                var channels = ChannelServices.RegisteredChannels;
                if (!Array.Exists(channels, x => x.ChannelName == "RemotingServices"))
                {
                    //信道端口
                    IDictionary idic = new Hashtable();
                    idic["port"] = _config.LocalPort;
                    idic["name"] = "RemotingServices";
                    tcpchannel   = new TcpChannel(idic, clientProvider, serverProvider);
                    ChannelServices.RegisterChannel(tcpchannel, false);
                }
                Connect();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            var serverProv = new BinaryServerFormatterSinkProvider {
                TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full
            };
            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
            IDictionary props = new Hashtable();

            props["port"] = 55555;
            TcpChannel channel = new TcpChannel(props, clientProv, serverProv);

            ChannelServices.RegisterChannel(channel, false);


            DependencyInjector.InjectDependencies();
            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs eventArgs)
            {
                QuitEvent.Set();
                eventArgs.Cancel = true;
            };
            new Thread(async() =>
            {
                var server = DependencyInjector.ServiceProvider.Resolve <Server>();
                await server.StartServer();
            }).Start();

            QuitEvent.WaitOne();
        }
        static void Main(string[] args)
        {
            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();

            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
            IDictionary props = new Hashtable();

            props["port"] = 55555;
            TcpChannel channel = new TcpChannel(props, clientProv, serverProv);

            ChannelServices.RegisterChannel(channel, false);

            ClientRepository clientRepository = new ClientRepository();
            MatchRepository  matchRepository  = new MatchRepository();
            SellerRepository sellerRepository = new SellerRepository();
            TicketRepository ticketRepository = new TicketRepository();
            var server = new ServiceImpl(clientRepository, matchRepository, sellerRepository, ticketRepository);

            //var server = new ChatServerImpl();
            RemotingServices.Marshal(server, "Chat");
            //RemotingConfiguration.RegisterWellKnownServiceType(typeof(ChatServerImpl), "Chat",
            //    WellKnownObjectMode.Singleton);

            // the server will keep running until keypress.
            Console.WriteLine("Server started ...");
            Console.WriteLine("Press <enter> to exit...");
            Console.ReadLine();
        }
Esempio n. 7
0
        private void MakeConnectionToServer(string IP)
        {
            try
            {
                BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
                BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
                serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                IDictionary props = new Hashtable();
                props["port"] = 0;
                string s = System.Guid.NewGuid().ToString();
                props["name"]            = s;
                props["typeFilterLevel"] = TypeFilterLevel.Full;

                HttpChannel chan = new HttpChannel(props, clientProvider, serverProvider);

                int Port = 9999;
                ChannelServices.RegisterChannel(chan);
                obj = (IRemote)Activator.GetObject(typeof(IRemote), "http://" + IP + ":" + Port + "/RemoteObject.soap", WellKnownObjectMode.SingleCall);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to connect to server");
            }
        }
Esempio n. 8
0
        private void RegisterRemotingServerChannel()
        {
            if (m_remotingChannel == null)
            {
                BinaryClientFormatterSinkProvider clientSinkProvider = new BinaryClientFormatterSinkProvider();

                BinaryServerFormatterSinkProvider serverSinkProvider = new BinaryServerFormatterSinkProvider
                {
                    TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full
                };

                Hashtable channelProperties = new Hashtable
                {
                    ["port"] = 8085
                };

                m_remotingChannel = new TcpChannel(channelProperties, clientSinkProvider, serverSinkProvider);
                // Setup remoting server
                try
                {
#if NET_2_0 || MONO_2_0 || MONO_3_5 || MONO_4_0
                    ChannelServices.RegisterChannel(m_remotingChannel, false);
#else
                    ChannelServices.RegisterChannel(m_remotingChannel);
#endif
                }
                catch (Exception ex)
                {
                    Assert.Fail("Failed to set up LoggingSink: {0}", ex);
                }

                // Marshal the sink object
                RemotingServices.Marshal(RemoteLoggingSinkImpl.Instance, "LoggingSink", typeof(RemotingAppender.IRemoteLoggingSink));
            }
        }
        /**
         *   Activate/Deactivate server
         */

        public NetworkBackgammonRemoteGameRoom ActivateServer(string port)
        {
            if (m_channel == null)
            {
                // We need to use binary formatters, which allow the serialization of generic collections
                BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
                serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();

                IDictionary props = new Hashtable();
                props["port"] = Convert.ToInt32(port);
                props["name"] = String.Empty;

                m_channel = new HttpChannel(props, clientProv, serverProv);
            }
            ChannelServices.RegisterChannel(m_channel, false);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(NetworkBackgammonRemoteGameRoom), "GameRoom", WellKnownObjectMode.Singleton);

            // Assign the instantiated remote server to the local server
            MarshalByRefObject obj = (MarshalByRefObject)RemotingServices.Connect(typeof(NetworkBackgammonRemoteGameRoom), "http://127.0.0.1:" + port + "/GameRoom");

            gameRoom = obj as NetworkBackgammonRemoteGameRoom;

            return(gameRoom);
        }
Esempio n. 10
0
        // 开启客户端
        private void StartClient()
        {
            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
            BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();

            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;

            IDictionary props = new Hashtable();

            props["port"] = 0;
            TcpChannel channel = new TcpChannel(props, clientProvider, serverProvider);

            ChannelServices.RegisterChannel(channel);

            //// 配置通道及传输格式
            //string cfg = "Client.config";
            //RemotingConfiguration.Configure(cfg);

            // 由config中读取相关数据
            string broadCastObjURL = ConfigurationManager.AppSettings["BroadCastObjURL"];

            // 获取广播远程对象
            watch = (IBroadCast)Activator.GetObject(typeof(IBroadCast), broadCastObjURL);

            wrapper = new EventWrapper();
            wrapper.LocalBroadCastEvent += new BroadCastEventHandler(BroadCastingMessage);
            watch.BroadCastEvent        += new BroadCastEventHandler(wrapper.BroadCasting);
            SetSubscribe(true);
        }
Esempio n. 11
0
        public bool Initialize(int iPort)
        {
            bool fRet = true;

            try
            {
                BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
                serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
                IDictionary props = new Hashtable();
                props["port"] = iPort;
                TcpChannel tcpChannel = new TcpChannel(props, clientProv, serverProv);
                ChannelServices.RegisterChannel(tcpChannel, true);
            }
            catch (RemotingException)
            {
                fRet = false;
            }
            catch (System.Net.Sockets.SocketException)
            {
                fRet = false;
            }
            catch (Exception)
            {
                fRet = false;
            }
            m_fReady = fRet;

            return(fRet);
        }
Esempio n. 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientFrm"/> class.
        /// </summary>
        /// <param name="username">The username<see cref="string"/></param>
        public ClientFrm(string username)
        {
            try
            {
                InitializeComponent();
                this.username = username;
                clientProv    = new BinaryClientFormatterSinkProvider();
                serverProv    = new BinaryServerFormatterSinkProvider();
                serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;



                eventProxy = new EventProxy();
                eventProxy.MessageArrived += new MessageArrivedEvent(eventProxy_MessageArrived);

                Hashtable props = new Hashtable();
                props["name"] = "remotingClient";
                props["port"] = 0;      //First available port

                tcpChan = new TcpChannel(props, clientProv, serverProv);
                ChannelServices.RegisterChannel(tcpChan);

                RemotingConfiguration.RegisterWellKnownClientType(new WellKnownClientTypeEntry(typeof(IServerObject), serverURI));
            }
            catch (Exception ex)
            {
                ErrorLogger.ErrorLog(ex);
            }
        }
Esempio n. 13
0
        private void Form1_Load(object sender, EventArgs e)
        {
            BinaryServerFormatterSinkProvider serverProvider = new
                                                               BinaryServerFormatterSinkProvider();
            BinaryClientFormatterSinkProvider clientProvider = new
                                                               BinaryClientFormatterSinkProvider();

            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;

            IDictionary props = new Hashtable();

            props["port"] = 0;
            HttpChannel channel = new HttpChannel(props, clientProvider, serverProvider);

            ChannelServices.RegisterChannel(channel, false);

            watch = (IBroadCast)Activator.GetObject(
                typeof(IBroadCast), "http://localhost:8080/BroadCastMessage.soap");

            wrapper = new EventWrapper();
            wrapper.LocalBroadCastEvent += new BroadCastEventHandler(BroadCastingMessage);
            watch.BroadCastEvent        += new BroadCastEventHandler(wrapper.BroadCasting);

            //watch.BroadCastEvent += new BroadCastEventHandler(BroadCastingMessage);
        }
Esempio n. 14
0
        static void InitialServer()
        {
            IDictionary dictionary = new Hashtable();

            dictionary["port"] = 8501;

            //服务端通道格式接收器
            BinaryServerFormatterSinkProvider severFormatter;

            severFormatter = new BinaryServerFormatterSinkProvider();
            severFormatter.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            //客户端通道格式接收器
            BinaryClientFormatterSinkProvider clientFormatter = new BinaryClientFormatterSinkProvider();

            //1.创建通道示例
            IChannel channel = new TcpChannel(dictionary, clientFormatter, severFormatter);

            //2.注册通道
            ChannelServices.RegisterChannel(channel, false);


            //3.注册服务对象类型
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(Server), "ServerActivated", WellKnownObjectMode.Singleton);
            RemotingConfiguration.ApplicationName = "RemoteCallbackServer";

            Console.WriteLine("方式: Server Activated Singleton");
            Console.WriteLine("服务已启动");

            Console.ReadLine();
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
            IDictionary pro = new Hashtable();

            pro["port"] = 55555;
            TcpChannel channel = new TcpChannel(pro, clientProvider, serverProvider);

            ChannelServices.RegisterChannel(channel, false);


            IDictionary <string, string> props = new Dictionary <string, string>();

            props.Add("connectionString", GetConnectionStringByName("excursiiDB"));

            IAgentRepository     agentRepository     = new RepositoryAgent(props);
            IRezervareRepository rezervareRepository = new RepositoryRezervare(props);
            IExcursieRepository  excursieRepository  = new RepositoryExcursie(props);
            Service s = new Service(agentRepository, excursieRepository, rezervareRepository);

            RemotingServices.Marshal(s, "app");

            // SerialServer server = new SerialServer("127.0.0.1", 55555, s);
            // server.Start();
            Console.WriteLine("Server started ...");

            Console.ReadLine();
        }
Esempio n. 16
0
        public RemotingHostServer(Machine machine, int port, string name)
            : base(machine)
        {
            this.port = port;
            this.name = name;
            // TODO review this name, get machine name
            this.hostname = "localhost";
            // According to http://www.thinktecture.com/resourcearchive/net-remoting-faq/changes2003
            // in order to have ObjRef accessible from client code
            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();

            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();

            IDictionary props = new Hashtable();

            props["port"] = port;

            TcpChannel channel = new TcpChannel(props, clientProv, serverProv);

            // end of "according"

            // TODO review other options to publish an object
            this.objref = RemotingServices.Marshal(this, name);
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure(new System.IO.FileInfo(args[0]));
            Console.WriteLine("Configuration Settings for database {0}", GetConnectionStringByName("database"));
            IDictionary <String, string> props = new SortedList <String, String>();

            props.Add("ConnectionString", GetConnectionStringByName("database"));

            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
            IDictionary dictionary = new Hashtable();

            dictionary["port"] = 55555;
            TcpChannel channel = new TcpChannel(dictionary, clientProvider, serverProvider);

            ChannelServices.RegisterChannel(channel, false);

            AngajatRepository angajatRepo = new AngajatRepository(props);
            IZborRepo         zborRepo    = new ZborRepository(props);
            IClientRepo       clientRepo  = new ClientRepository(props);
            IBiletRepo        biletRepo   = new BiletRepository(props);

            var server = new FlightServerImpl(angajatRepo, zborRepo, clientRepo, biletRepo);

            RemotingServices.Marshal(server, "zboruri");

            Console.WriteLine("Server started ...");
            Console.ReadLine();
        }
Esempio n. 18
0
        public LoginPage()
        {
            Text = "Chat Service Login/Register";
            Console.WriteLine("Client starting ...");
            InitializeComponent();

            clientProv = new BinaryClientFormatterSinkProvider();
            serverProv = new BinaryServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;


            Hashtable props = new Hashtable();

            props["name"] = "remotingClient";
            props["port"] = 0;      //First available port

            tcpChan = new TcpChannel(props, clientProv, serverProv);
            ChannelServices.RegisterChannel(tcpChan, false);

            RemotingConfiguration.RegisterWellKnownClientType(new WellKnownClientTypeEntry(typeof(IServerObject), serverURI));

            try
            {
                remoteServer = (IServerObject)Activator.GetObject(typeof(IServerObject), serverURI);
                Console.WriteLine(remoteServer.HelloWorld());
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not connect: " + ex.Message);
            }
        }
Esempio n. 19
0
        internal static bool ConfigureRemoting(int port, string ipToBind)
        {
            BinaryClientFormatterSinkProvider clientProvider = null;
            BinaryServerFormatterSinkProvider serverProvider =
                new BinaryServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel =
                System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            IDictionary props = new Hashtable();

            props["port"]            = port;
            props["typeFilterLevel"] = TypeFilterLevel.Full;

            if (!string.IsNullOrEmpty(ipToBind))
            {
                mLog.InfoFormat("Binding the ip to {0}", ipToBind);
                props["bindTo"] = ipToBind;
            }

            try
            {
                TcpChannel chan = new TcpChannel(
                    props, clientProvider, serverProvider);

                mLog.DebugFormat("Registering channel on port {0}", port);
                ChannelServices.RegisterChannel(chan, false);
                return(true);
            }
            catch (Exception e)
            {
                mLog.InfoFormat("Can't register channel.\n{0}", e.Message);
                return(false);
            }
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            Persistence.Repository.RepoAvailableRoomDB repoAR  = new Persistence.Repository.RepoAvailableRoomDB();
            Persistence.Repository.RepoConference      repoC   = new Persistence.Repository.RepoConference();
            Persistence.Repository.RepoMessageDB       repoM   = new Persistence.Repository.RepoMessageDB();
            Persistence.Repository.RepoPaperDB         repoPap = new Persistence.Repository.RepoPaperDB();
            Persistence.Repository.RepoParticipantDB   repoPar = new Persistence.Repository.RepoParticipantDB();
            Persistence.Repository.RepoPayment         repoPay = new Persistence.Repository.RepoPayment();
            Persistence.Repository.RepoUserDB          repoU   = new Persistence.Repository.RepoUserDB();
            Persistence.RepoSessionDB repoS = new Persistence.RepoSessionDB();

            BinaryServerFormatterSinkProvider servProv = new BinaryServerFormatterSinkProvider();

            servProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
            IDictionary props = new Hashtable();

            props["port"] = 11111;
            TcpChannel channel = new TcpChannel(props, clientProv, servProv);

            ChannelServices.RegisterChannel(channel, false);

            var server = new ServerImplementation(repoU, repoAR, repoC, repoM, repoPap, repoPar, repoPay, repoS);

            RemotingServices.Marshal(server, "Conferences");

            Console.WriteLine("Server go");
            Console.ReadLine();
        }
Esempio n. 21
0
        private static void CreateChannel()
        {
            if (_channel != null)
            {
                return;
            }
            _channelType = typeof(CommandWorker);
            var type      = typeof(CommandWorker);
            var portName  = $"{type.FullName.Replace(".", "-").ToLower()}-{Guid.NewGuid()}";
            var objectUri = type.Name.ToLower();
            var client    = new BinaryClientFormatterSinkProvider();
            var server    = new BinaryServerFormatterSinkProvider {
                TypeFilterLevel = TypeFilterLevel.Full
            };
            var config = new Hashtable {
                ["name"]     = string.Empty,
                ["portName"] = portName,
                ["tokenImpersonationLevel"] = TokenImpersonationLevel.Impersonation,
                ["impersonate"]             = true,
                ["useDefaultCredentials"]   = true,
                ["secure"]          = true,
                ["typeFilterLevel"] = TypeFilterLevel.Full
            };

            _channel = new IpcChannel(config, client, server);
            ChannelServices.RegisterChannel(_channel, true);
            RemotingConfiguration.RegisterWellKnownServiceType(_channelType, objectUri, WellKnownObjectMode.SingleCall);
        }
Esempio n. 22
0
        static void Main(string[] args)
        {
            //IServices services = new Services();
            //FlightsAppServer server = new FlightsAppServer("127.0.0.1", 4444, services);
            //server.Start();
            //Console.WriteLine("Server started ...");

            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();

            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();

            IDictionary props = new Hashtable();

            props["port"] = 55555;

            TcpChannel channel = new TcpChannel(props, clientProv, serverProv);

            ChannelServices.RegisterChannel(channel, false);


            var server = new Services();

            //var server = new ChatServerImpl();
            RemotingServices.Marshal(server, "Chat");
            //RemotingConfiguration.RegisterWellKnownServiceType(typeof(ChatServerImpl), "Chat",
            //    WellKnownObjectMode.Singleton);

            // the server will keep running until keypress.
            Console.WriteLine("Server started ...");
            Console.WriteLine("Press <enter> to exit...");
            Console.ReadLine();
        }
Esempio n. 23
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private RemoteObject GetRemoteObject()
        {
            if (_remoteObject == null)
            {
                IDictionary tcpProperties = new Hashtable();

                BinaryClientFormatterSinkProvider tcpClientSinkProvider =
                    new BinaryClientFormatterSinkProvider();

                BinaryServerFormatterSinkProvider tcpServerSinkProvider =
                    new BinaryServerFormatterSinkProvider();

                tcpServerSinkProvider.TypeFilterLevel =
                    System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                tcpProperties["timeout"] = 5000;
                tcpProperties["port"]    = 0;

                _tcpChannel = new TcpChannel(
                    tcpProperties,
                    tcpClientSinkProvider,
                    tcpServerSinkProvider);

                ChannelServices.RegisterChannel(_tcpChannel, false);


                _remoteObject = (RemoteObject)Activator.GetObject(
                    typeof(RemoteObject),
                    "tcp://127.0.0.1:9000/RO"
                    );
            }

            return(_remoteObject);
        }
Esempio n. 24
0
 /// <summary>
 /// 注册通道
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Client_Load(object sender, EventArgs e)
 {
     try
     {
         //设置反序列化级别
         BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
         BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
         serverProvider.TypeFilterLevel = TypeFilterLevel.Full;//支持所有类型的反序列化,级别很高
         //信道端口
         IDictionary idic = new Dictionary <string, string>();
         idic["name"] = "clientHttp";
         idic["port"] = "0";
         HttpChannel channel = new HttpChannel(idic, clientProvider, serverProvider);
         ChannelServices.RegisterChannel(channel, false);
         _remotingObject = (IRemotingObject)Activator.GetObject(typeof(IRemotingObject), "http://localhost:8022/SumMessage");
         //_remotingObject.ServerToClient += (info, toName) => { rtxMessage.AppendText(info + "\r\n"); };
         SwapObject swap = new SwapObject();
         _remotingObject.ServerToClient += swap.ToClient;
         swap.SwapServerToClient        += (info, toName) =>
         {
             rtxMessage.Invoke((MethodInvoker)(() =>
             {
                 if (toName == txtLogin.Text || toName == "")
                 {
                     rtxMessage.AppendText(info + "\r\n");
                 }
             }));
         };
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 25
0
        /// <summary>
        /// Create a <see cref="TcpChannel"/> with a given name on a given port.
        /// </summary>
        /// <param name="name">The name of the channel to create.</param>
        /// <param name="port">The port number of the channel to create.</param>
        /// <param name="limit">The rate limit of the channel to create.</param>
        /// <param name="currentMessageCounter">An optional counter to provide the ability to wait for all current messages.</param>
        /// <returns>A <see cref="TcpChannel"/> configured with the given name and port.</returns>
        private static TcpChannel CreateTcpChannel(string name, int port, int limit, CurrentMessageCounter currentMessageCounter = null)
        {
            var props = new Dictionary <string, object>
            {
                { "port", port },
                { "name", name },
                { "bindTo", "127.0.0.1" },
                //{ "clientConnectionLimit", limit }
            };

            var serverProvider = new BinaryServerFormatterSinkProvider
            {
                TypeFilterLevel = TypeFilterLevel.Full
            };

            var clientProvider = new BinaryClientFormatterSinkProvider();

            return(new TcpChannel(
                       props,
                       clientProvider,
                       currentMessageCounter != null
                    ? new ObservableServerChannelSinkProvider(currentMessageCounter)
            {
                Next = serverProvider
            }
                    : (IServerChannelSinkProvider)serverProvider));
        }
Esempio n. 26
0
        private static void RegisterChannel(bool ipc)
        {
            BinaryServerFormatterSinkProvider serverProvider =
                new BinaryServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProvider =
                new BinaryClientFormatterSinkProvider();
            Dictionary <string, string> properties = new Dictionary <string, string>();
            IChannel channel;

            if (ipc)
            {
                properties["portName"] = CommConstants.ServerIPC + Util.DriverPort.ToString();
                properties["name"]     = "GFIpcChannel";
                channel = new IpcChannel(properties, clientProvider, serverProvider);
            }
            else
            {
                properties["port"] = Util.DriverPort.ToString();
                properties["name"] = "GFTcpChannel";
                channel            = new TcpChannel(properties, clientProvider, serverProvider);
            }
            ChannelServices.RegisterChannel(channel, false);
        }
Esempio n. 27
0
        /// <summary>
        ///  Create a TcpChannel with a given name, on a given port.
        /// </summary>
        /// <param name="port"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private static TcpChannel CreateTcpChannel(string name, int port, int limit)
        {
            ListDictionary props = new ListDictionary();

            props.Add("port", port);
            props.Add("name", name);
            props.Add("bindTo", "127.0.0.1");

            BinaryServerFormatterSinkProvider serverProvider =
                new BinaryServerFormatterSinkProvider();

            // NOTE: TypeFilterLevel and "clientConnectionLimit" property don't exist in .NET 1.0.
            Type typeFilterLevelType = typeof(object).Assembly.GetType("System.Runtime.Serialization.Formatters.TypeFilterLevel");

            if (typeFilterLevelType != null)
            {
                PropertyInfo typeFilterLevelProperty = serverProvider.GetType().GetProperty("TypeFilterLevel");
                object       typeFilterLevel         = Enum.Parse(typeFilterLevelType, "Full");
                typeFilterLevelProperty.SetValue(serverProvider, typeFilterLevel, null);

//                props.Add("clientConnectionLimit", limit);
            }

            BinaryClientFormatterSinkProvider clientProvider =
                new BinaryClientFormatterSinkProvider();

            return(new TcpChannel(props, clientProvider, serverProvider));
        }
Esempio n. 28
0
        // Server
        public bool Listen()
        {
            string port = ConfigurationManager.AppSettings["RemotingListenPort"];
            //string port = WebConfig.RemotingListenPort;
            bool conneted = false;

            try
            {
                BinaryClientFormatterSinkProvider clientProvider = null;
                BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
                serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                IDictionary props = new Hashtable();
                props["port"]            = port;
                props["typeFilterLevel"] = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                TcpChannel channel = new TcpChannel(props, clientProvider, serverProvider);

                ChannelServices.RegisterChannel(channel, false);

                Console.WriteLine("Listening for Remote Service on Port:{0}", props["port"]);
                conneted = true;
            }

            catch (Exception ex)
            {
                Console.WriteLine("Error Listening for Remote Service on Port:{0} Error:{1}", port, ex.Message);
            }

            return(conneted);
        }
        public override bool openConnection(int aPort)
        {
            try
            {
                //Configure remoting.
                BinaryServerFormatterSinkProvider serverFormatter =
                    new BinaryServerFormatterSinkProvider();

                serverFormatter.TypeFilterLevel = TypeFilterLevel.Full;

                BinaryClientFormatterSinkProvider clientProv =
                    new BinaryClientFormatterSinkProvider();

                Hashtable props = new Hashtable();
                props["name"] = RemotingObjectName;
                props["port"] = 0;

                mpChannel = new TcpChannel(props, clientProv, serverFormatter);

                ChannelServices.RegisterChannel(mpChannel, false);
                return(true);
            }
            catch (Exception)
            {
                if (mpChannel != null)
                {
                    ChannelServices.UnregisterChannel(mpChannel);
                    mpChannel = null;
                }
            }
            return(false);
        }
Esempio n. 30
0
        // Initialise the remoting connection with http channel with binary formatter
        public bool RemotingConnection()
        {
            if (!_exist)
            {
                HttpChannel channel = null;
                try
                {
                    IDictionary props = new Hashtable();
                    props["port"] = TechnicalSettings.RemotingServerPort;
                    props.Add("typeFilterLevel", TypeFilterLevel.Full);
                    //props.Add("timeout", 2000);
                    BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
                    channel = new HttpChannel(props, clientProvider, null);
                    ChannelServices.RegisterChannel(channel, false);

                    //TcpChannel channel = new TcpChannel();
                    //ChannelServices.RegisterChannel(channel, true);
                    var server = string.Format("http://{0}:{1}/RemoteOperation", TechnicalSettings.RemotingServer,
                                               TechnicalSettings.RemotingServerPort);

                    _remoteOperation = (IRemoteOperation)Activator.GetObject(typeof(IRemoteOperation), server);
                    _exist           = _remoteOperation.TestRemoting();

                    //ChannelServices.GetChannelSinkProperties(_remoteOperation)["timeout"] = 0;
                }
                catch (Exception e)
                {
                    _remotingUniqueInstance = null;
                    ChannelServices.UnregisterChannel(channel);
                    throw;
                }
            }
            return(true);
        }
Esempio n. 31
0
        public static IClientChannelSinkProvider ClientChannelCreateSinkProviderChain(
			IClientChannelSinkProvider formatterSinkProvider,
			IClientChannelSinkProvider transportSinkProvider)
        {
            // we use MSFT BinaryFormatter by default for maximum compatibility
            if (formatterSinkProvider == null)
            {
                formatterSinkProvider = new BinaryClientFormatterSinkProvider();
            }

            // set transport provider to be the last in the chain
            IClientChannelSinkProvider sinkProvider = formatterSinkProvider;
            while (sinkProvider.Next != null)
            {
                sinkProvider = sinkProvider.Next;
            }
            sinkProvider.Next = transportSinkProvider;

            return formatterSinkProvider;
        }
Esempio n. 32
0
	static string RegisterRemotingChannel ()
	{
		IDictionary formatterProps = new Hashtable ();
		formatterProps ["includeVersions"] = false;
		formatterProps ["strictBinding"] = false;
		
		IDictionary dict = new Hashtable ();
		BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider(formatterProps, null);
		BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider(formatterProps, null);
		serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
		
		// Mono's and .NET's IPC channels have interoperability issues, so use TCP in this case
		if (CurrentRuntime != ParentRuntime) {
			// Running Mono on Windows
			dict ["port"] = 0;
			dict ["rejectRemoteRequests"] = true;
			ChannelServices.RegisterChannel (new TcpChannel (dict, clientProvider, serverProvider), false);
			return null;
		}
		else {
			string unixRemotingFile = Path.GetTempFileName ();
			dict ["portName"] = Path.GetFileName (unixRemotingFile);
			ChannelServices.RegisterChannel (new IpcChannel (dict, clientProvider, serverProvider), false);
			return unixRemotingFile;
		}
	}
Esempio n. 33
0
    /// <summary>
    /// Access the .NET Remoting server using code.
    /// </summary>
    static void RemotingClientByCode()
    {
        /////////////////////////////////////////////////////////////////////
        // Create and register a channel (TCP channel in this example) that
        // is used to transport messages across the remoting boundary.
        //

        // Properties of the channel
        IDictionary props = new Hashtable();
        props["typeFilterLevel"] = TypeFilterLevel.Full;

        // Formatters of the messages for delivery
        BinaryClientFormatterSinkProvider clientProvider =
            new BinaryClientFormatterSinkProvider();
        BinaryServerFormatterSinkProvider serverProvider =
            new BinaryServerFormatterSinkProvider();
        serverProvider.TypeFilterLevel = TypeFilterLevel.Full;

        // Create a TCP channel
        TcpChannel tcpChannel = new TcpChannel(props, clientProvider,
            serverProvider);

        // Register the TCP channel
        ChannelServices.RegisterChannel(tcpChannel, true);

        /////////////////////////////////////////////////////////////////////
        // Create a remotable object.
        //

        // Create a SingleCall server-activated object
        SingleCallObject remoteObj = (SingleCallObject)Activator.GetObject(
            typeof(SingleCallObject),
            "tcp://localhost:6100/SingleCallService");

        // [-or-] a Singleton server-activated object
        //SingletonObject remoteObj = (SingletonObject)Activator.GetObject(
        //    typeof(SingletonObject),
        //    "tcp://localhost:6100/SingletonService");

        // [-or-] a client-activated object
        //RemotingConfiguration.RegisterActivatedClientType(
        //    typeof(ClientActivatedObject),
        //    "tcp://localhost:6100/RemotingService");
        //ClientActivatedObject remoteObj = new ClientActivatedObject();

        /////////////////////////////////////////////////////////////////////
        // Use the remotable object as if it were a local object.
        //

        string remoteType = remoteObj.GetRemoteObjectType();
        Console.WriteLine("Call GetRemoteObjectType => {0}", remoteType);

        Console.WriteLine("The client process and thread: {0}, {1}",
            GetCurrentProcessId(), GetCurrentThreadId());

        uint processId, threadId;
        remoteObj.GetProcessThreadID(out processId, out threadId);
        Console.WriteLine("Call GetProcessThreadID => {0} {1}", processId, threadId);

        Console.WriteLine("Set FloatProperty += {0}", 1.2f);
        remoteObj.FloatProperty += 1.2f;

        Console.WriteLine("Get FloatProperty = {0}", remoteObj.FloatProperty);
    }
	static string RegisterRemotingChannel ()
	{
		IDictionary dict = new Hashtable ();
		BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
		BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
		string unixRemotingFile = Path.GetTempFileName ();
		dict ["portName"] = Path.GetFileName (unixRemotingFile);
		serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
		ChannelServices.RegisterChannel (new IpcChannel (dict, clientProvider, serverProvider), false);
		return unixRemotingFile;
	}