Inheritance: IClientFormatterSinkProvider
Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("id machine Ex: http://localhost:12344");
            String id = "http://localhost:12344";

            string configfile = "Server2.exe.config";
            //RemotingConfiguration.Configure(configfile, false);

            SoapServerFormatterSinkProvider serverProv = new SoapServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            SoapClientFormatterSinkProvider clientProv = new SoapClientFormatterSinkProvider();
            IDictionary props = new Hashtable();
            props["port"] = 12344;
            HttpChannel ch = new HttpChannel(props, clientProv, serverProv);
            //HttpChannel ch = new HttpChannel(1234);
            ChannelServices.RegisterChannel(ch, false);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ServerClass2.Server), "RemoteServer2.soap", WellKnownObjectMode.Singleton);

            //HttpChannel ch = new HttpChannel(1);
            //ChannelServices.RegisterChannel(ch, false);

            IManager manager = (IManager)Activator.GetObject(typeof(IManager), "http://localhost:1234/RemoteManager.soap");

            manager.Register(id + "/RemoteServer2.soap");

            Console.WriteLine("Server start");
            Console.ReadLine();

            manager.UnRegister(id + "/RemoteServer2.soap");
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            SoapServerFormatterSinkProvider serverProv = new SoapServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            SoapClientFormatterSinkProvider clientProv = new SoapClientFormatterSinkProvider();

            IDictionary props = new Hashtable();
            props["port"] = 0;
            HttpChannel ch = new HttpChannel(props,clientProv,serverProv);
            // Se usar TcpChannel não esqueça de mudar o URL de activação para "tcp://localhost......"
            //TcpChannel ch = new TcpChannel(props, clientProv, serverProv);
            ChannelServices.RegisterChannel(ch,false);

            Console.WriteLine("Vai criar Alunos Factory\n");
            IRemAlunoFactory fact = (IRemAlunoFactory) Activator.GetObject(
                typeof(IRemAlunoFactory),
                "http://localhost:1234/RemoteAlunoFactory.soap");

            Console.WriteLine("Vai criar Aluno com nome\n");
            IRemAluno jose = fact.getNewInstanceAluno("jose");

            //Console.ReadLine();
            Console.WriteLine("{0}: Criação do objecto com sponsor.", DateTime.Now);
            //MySponsor sponsorjose = new MySponsor();  // Sponsor client-side !!! problemas nalgumas máquinas
            //IGenericSponsor sponsorjose = fact.getGenericSponsor(); // Sponsor server-side
            //ILease leasejose = (ILease)RemotingServices.GetLifetimeService((MarshalByRefObject)jose);
            //leasejose.Register(sponsorjose);

            try {
                  for (int i=0;i<10;i++) {
                     Console.WriteLine(i+"> "+jose.alunoHello());
                     //if (i == 7) sponsorjose.setNotRenew();
                     Thread.Sleep((i+1)*2000);
                  }
            } catch (Exception e) {
                Console.WriteLine("Fim de vida do objecto Aluno:{0}",e.Message);
            }

            Console.ReadLine();
            //leasejose.Unregister(sponsorjose);
        }
Ejemplo n.º 3
0
        static void Main( )
        {
            //BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
            //serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            //BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();

            SoapServerFormatterSinkProvider serverProv = new SoapServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            SoapClientFormatterSinkProvider clientProv = new SoapClientFormatterSinkProvider();
            IDictionary props = new Hashtable();
            props["port"] = 0;
            HttpChannel ch = new HttpChannel(props, clientProv, serverProv);
               // HttpChannel ch = new HttpChannel(0);
            ChannelServices.RegisterChannel(ch, false);
            IServer svc = (IServer)Activator.GetObject(
                typeof(IServer),
                "http://localhost:1234/RemoteServer.soap");

            //RemotingConfiguration.Configure("ClientePingPong.exe.config", false);
            //WellKnownClientTypeEntry[] entries =
            //    RemotingConfiguration.GetRegisteredWellKnownClientTypes();
            //IServer svc = (IServer)Activator.GetObject(
            //    entries[0].ObjectType,
            //    entries[0].ObjectUrl);

            //Console.ReadLine();
            IPingPong pp = new PingPongImpl(); pp.EstPing=true;
            try
            {
                for (int i = 0; i < 10; i++)
                    svc.FazPingPong(pp);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message+"\n"+ex.StackTrace);
            }
            Console.WriteLine("Prima Enter");
            Console.ReadLine();
        }
Ejemplo n.º 4
0
        static void Main()
        {
            //BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
            //serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            //BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();

            SoapServerFormatterSinkProvider serverProv = new SoapServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            SoapClientFormatterSinkProvider clientProv = new SoapClientFormatterSinkProvider();
            IDictionary props = new Hashtable();
            props["port"] = 1234;
            HttpChannel ch = new HttpChannel(props, clientProv, serverProv);
            //HttpChannel ch = new HttpChannel(1234);
            ChannelServices.RegisterChannel(ch, false);

            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(RemoteServer),
                "RemoteServer.soap",
                WellKnownObjectMode.Singleton);
            // Espera pedidos
            Console.WriteLine("Server: Espera pedidos...Prima Enter para terminar\n");

            Console.ReadLine();
        }
        } // CreateMessageSink


        //
        // end of IChannelSender implementation
        //


        private IClientChannelSinkProvider CreateDefaultClientProviderChain()
        {
            IClientChannelSinkProvider chain = new SoapClientFormatterSinkProvider();            
            IClientChannelSinkProvider sink = chain;
            
            sink.Next = new HttpClientTransportSinkProvider(_timeout);
            
            return chain;
        } // CreateDefaultClientProviderChain
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            ServerEndPoint servidor;
            //carregar tabela com links para servidores
            foreach (DictionaryEntry server in (Hashtable)ConfigurationSettings.GetConfig("servidores"))
                servidores.Add((string)server.Key, new ServerEndPoint((string)server.Key, (string)server.Value));

            if (args.Length != 1)
            {
                Random r = new Random();
                Console.WriteLine("A que servidor se pretende ligar?:");

                foreach(ServerEndPoint sp in servidores.Values)
                    Console.WriteLine(sp.Name);

                servidor = null;
                do
                {
                    string serv = Console.ReadLine();
                    servidor = (ServerEndPoint) servidores[serv];
                } while (servidor == null);
            }
            else
            {
                servidor = (ServerEndPoint)servidores[args[0]];
            }
            Console.WriteLine("A ligar ao servidor " + servidor.Name + " : " + servidor);
            IServerChannelSinkProvider serverProv;
            IClientChannelSinkProvider clientProv;
            IChannel hch;
            IDictionary props = new Hashtable();
            props["port"] = 0;
            switch (servidor.Uri.Scheme)
            {
                case "http":
                case "https":
                    // Creating a custom formatter for a HttpChannel sink chain.
                    serverProv = new SoapServerFormatterSinkProvider();
                    ((SoapServerFormatterSinkProvider)serverProv).TypeFilterLevel =
                        System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                    clientProv = new SoapClientFormatterSinkProvider();
                    hch = new HttpChannel(props, clientProv, serverProv);

                    break;
                case "tcp":
                    // Creating a custom formatter for a TcpChannel sink chain.
                    serverProv = new BinaryServerFormatterSinkProvider();
                    ((BinaryServerFormatterSinkProvider)serverProv).TypeFilterLevel =
                        System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                    clientProv = new BinaryClientFormatterSinkProvider();
                    hch = new TcpChannel(props, clientProv, serverProv);
                    break;
                default:
                    throw new Exception("Tipo de url nao implementado");
            }
            ChannelServices.RegisterChannel(hch, false);
            IPublicServer robj = (IPublicServer)Activator.GetObject(
               typeof(IPublicServer),
               servidor.ToString());

            StartClientConsole(robj);

            //testar obter uma chave de outro servidores
            if (DEBUG)
            {
                robj.sayHelllo();
                Valor v;
            /*
                //teste single server
                IKey key = new MyKey("servidor1 key1", 10);
                IValue value = new Valor("servidor1 valor1", new int[] { 10, 10 });

                Console.WriteLine("Soring key1");
                robj.storePair(key, value);

                Console.WriteLine("Geting key1");
                v = (Valor) robj.readPair(key);

                Console.WriteLine("Deleting key1");
                robj.deletePair(key);

                Console.WriteLine("Soring key1");
                v = (Valor)robj.readPair(key);
                if (v != null) Console.Error.WriteLine("Obtido valor calor inesperado de key1");

                Console.WriteLine("geting key from server1");
                v = (Valor)robj.readPair(new MyKey("servidor1", 1));
                if (v != null)
                {
                    Console.WriteLine("obtida com sucesso");
                }
                else
                {
                    Console.WriteLine("obtida sem sucesso");
                }
                Console.WriteLine("geting key from server2");
                v = (Valor)robj.readPair(new MyKey("servidor2", 1));
                if (v != null)
                {
                    Console.WriteLine("obtida com sucesso");
                }
                else
                {
                    Console.WriteLine("obtida sem sucesso");
                }

                Console.WriteLine("geting key from server3");
                v = (Valor)robj.readPair(new MyKey("servidor3", 1));
                if (v != null)
                {
                    Console.WriteLine("obtida com sucesso");
                }
                else
                {
                    Console.WriteLine("obtida sem sucesso");
                }
                Console.WriteLine("A obter 3 veses a mesma chave remota");
                v = (Valor)robj.readPair(new MyKey("servidor3", 1));
                if (v == null) Console.WriteLine("erro");
                v = (Valor)robj.readPair(new MyKey("servidor3", 1));
                if (v == null) Console.WriteLine("erro");
                v = (Valor)robj.readPair(new MyKey("servidor3", 1));
                if (v == null) Console.WriteLine("erro");
                Console.WriteLine("fim das 3 obtencoes");
                */
                Console.WriteLine("Tentar atualizar um valor remoto");
                robj.sayHelllo();
                Thread.Sleep(1000);
                robj.readPair(new MyKey("servidor3", 1));
                robj.updatePair(new MyKey("servidor3", 1), new Valor("teste 3", new int[] { 10, 10 }));
                Thread.Sleep(100);
                v = (Valor)robj.readPair(new MyKey("servidor3", 1));
                if (v == null) Console.WriteLine("erro");

                robj.deletePair(new MyKey("servidor3", 1));
                v = (Valor)robj.readPair(new MyKey("servidor3", 1));
                if (v != null) Console.WriteLine("erro");

            }

            Console.WriteLine("get completed");
            Console.ReadLine();
        }
Ejemplo n.º 7
0
        static void Main()
        {
            SoapServerFormatterSinkProvider serverProv = new SoapServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            SoapClientFormatterSinkProvider clientProv = new SoapClientFormatterSinkProvider();
            IDictionary props = new Hashtable();
            props["port"] = 1234;
            HttpChannel ch = new HttpChannel(props,clientProv,serverProv);
            //TcpChannel ch = new TcpChannel(props, clientProv, serverProv);
            ChannelServices.RegisterChannel(ch, false);
               // Definição do tempo de polling do TTL dos objectos
               LifetimeServices.LeaseManagerPollTime=TimeSpan.FromSeconds(1);

            // Registar o type RemoteAlunoFactory como Server Activated Object (SAO)
            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(RemoteAlunoFactory),
                "RemoteAlunoFactory.soap",
                WellKnownObjectMode.Singleton);
                //WellKnownObjectMode.SingleCall);
            // Espera pedidos
            Console.WriteLine("Server: Espera pedidos...Prima Enter para terminar\n");

            Console.ReadLine();
        }
 private IClientChannelSinkProvider CreateDefaultClientProviderChain()
 {
     IClientChannelSinkProvider provider = new SoapClientFormatterSinkProvider();
     IClientChannelSinkProvider provider2 = provider;
     provider2.Next = new HttpClientTransportSinkProvider(this._timeout);
     return provider;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Erzeugt einen fertig konfigurierten Remoting-Kanal.
        /// <remarks>
        /// Wenn der Kanal in der aktuellen Anwendungsdomäne bereits registriert wurde, wird null zurückgegeben.
        /// </remarks>
        /// </summary>
        /// <returns>Remoting Kanal</returns>
        public IChannel CreateChannel()
        {
            // Kanal suchen
            IChannel channel = ChannelServices.GetChannel(_channelName);

            // Wenn der Kanal nicht gefunden wurde ...
            if (channel == null)
            {
                // Konfiguration für den HTTP-Kanal erstellen
                System.Collections.IDictionary channelSettings = new System.Collections.Hashtable();
                channelSettings["name"] = _channelName;
                channelSettings["port"] = 0;

                // Variable für Clientformatierer
                IClientFormatterSinkProvider clientFormatter = null;

                // Wenn binäre Formatierung verwendet werden soll ...
                if (_useBinaryFormatter)
                    // Binären Clientformatierer erzeugen
                    clientFormatter = new BinaryClientFormatterSinkProvider();
                else
                    // SOAP Clientformatierer erzeugen
                    clientFormatter = new SoapClientFormatterSinkProvider();

                // Wenn die Kommunikation verschlüsselt werden soll ...
                if (_encryption)
                {
                    // Client-Verschlüsselungs-Kanalsenkenanbieter erzeugen
                    CryptoClientChannelSinkProvider clientEncryption = new CryptoClientChannelSinkProvider();

                    // Verschlüsselung konfigurieren
                    clientEncryption.Algorithm = _algorithm;
                    clientEncryption.Oaep = _oaep;
                    clientEncryption.MaxAttempts = _maxAttempts;

                    // Verschlüsselungs-Kanalsenkenanbieter hinter den Formatierer hängen
                    clientFormatter.Next = clientEncryption;
                }
                // Variable für ersten Server-Senkenanbieter in der Kette
                IServerChannelSinkProvider firstServerSinkProvider = null;

                // Variable für Serverformatierer
                IServerFormatterSinkProvider serverFormatter = null;

                // Wenn binäre Formatierung verwendet werden soll ...
                if (_useBinaryFormatter)
                {
                    // Binären Serverformatierer erzeugen
                    serverFormatter = new BinaryServerFormatterSinkProvider();

                    // Serialisierung von komplexen Objekten aktivieren
                    ((BinaryServerFormatterSinkProvider)serverFormatter).TypeFilterLevel = TypeFilterLevel.Full;
                }
                else
                {
                    // SOAP Serverformatierer erzeugen
                    serverFormatter = new SoapServerFormatterSinkProvider();

                    // Serialisierung von komplexen Objekten aktivieren
                    ((SoapServerFormatterSinkProvider)serverFormatter).TypeFilterLevel = TypeFilterLevel.Full;
                }
                // Wenn die Kommunikation verschlüsselt werden soll ...
                if (_encryption)
                {
                    // Server-Verschlüsselungs-Kanalsenkenanbieter erzeugen
                    CryptoServerChannelSinkProvider serverEncryption = new CryptoServerChannelSinkProvider();

                    // Verschlüsselung konfigurieren
                    serverEncryption.Algorithm = _algorithm;
                    serverEncryption.Oaep = _oaep;
                    serverEncryption.RequireCryptoClient = true;

                    // Formatierer hinter den Verschlüsselungs-Kanalsenkenanbieter hängen
                    serverEncryption.Next = serverFormatter;

                    // Verschlüsselungs-Kanalsenkenanbieter als ersten Senkenanbieter festlegen
                    firstServerSinkProvider = serverEncryption;
                }
                else
                    // Server-Formatierer als ersten Senkenanbieter festlegen
                    firstServerSinkProvider = serverFormatter;

                // Neuen HTTP-Kanal erzeugen
                channel = new HttpChannel(channelSettings, clientFormatter, firstServerSinkProvider);

                // Wenn Zyan nicht mit mono ausgeführt wird ...
                if (!MonoCheck.IsRunningOnMono)
                {
                    // Sicherstellen, dass vollständige Ausnahmeinformationen übertragen werden
                    if (RemotingConfiguration.CustomErrorsMode != CustomErrorsModes.Off)
                        RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
                }
                // Kanal zurückgeben
                return channel;
            }
            // Nichts zurückgeben
            return null;
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            if (args.Length != 1) {
                Console.Error.WriteLine("Falta defenir o nome do servidor");
                System.Environment.Exit(1);
            }
            string nome_servidor = args[0];
            if (DEBUG) {
                foreach (Object seting in ConfigurationSettings.AppSettings) {
                    Console.WriteLine(seting);
                }
            }
            //carregar tabela com links para servidores
            foreach (DictionaryEntry server in (Hashtable)ConfigurationSettings.GetConfig("servidores")) {
                ServerEndPoint ep = new ServerEndPoint((string)server.Key, (string)server.Value);
                if (ep.Name == nome_servidor) {
                    //current endpoint
                    meuendpoint = ep;
                }
                else {
                    servidores.Add(ep.Name, ep);
                }
            }
            if (meuendpoint == null) {
                Console.Error.WriteLine("Nao foi encontrado configurações validas para o servidor " + nome_servidor);
            }
            else {
                // Restaurar dados do servidor do ultimo shutdown se existirem
                restoreServer(nome_servidor);

                IServerChannelSinkProvider serverProv;
                IClientChannelSinkProvider clientProv;
                IChannel hch;
                IDictionary props = new Hashtable();
                props["port"] = meuendpoint.Port;
                switch (meuendpoint.Uri.Scheme) {
                    case "http":
                    case "https":
                        // Creating a custom formatter for a HttpChannel sink chain.
                        serverProv = new SoapServerFormatterSinkProvider();
                        ((SoapServerFormatterSinkProvider)serverProv).TypeFilterLevel =
                            System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                        clientProv = new SoapClientFormatterSinkProvider();
                        hch = new HttpChannel(props, clientProv, serverProv);

                        break;
                    case "tcp":
                        // Creating a custom formatter for a TcpChannel sink chain.
                        serverProv = new BinaryServerFormatterSinkProvider();
                        ((BinaryServerFormatterSinkProvider)serverProv).TypeFilterLevel =
                            System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                        clientProv = new BinaryClientFormatterSinkProvider();
                        hch = new TcpChannel(props, clientProv, serverProv);
                        break;
                    default:
                        throw new Exception("Tipo de url nao implementado");
                }

                ChannelServices.RegisterChannel(hch, false);
                RemotingConfiguration.RegisterWellKnownServiceType(
                    typeof(Servidor),
                    meuendpoint.Uri.PathAndQuery.Substring(1),
                    WellKnownObjectMode.Singleton
                    );

                Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++");
                Console.WriteLine("Servidor: " + meuendpoint.Name);
                Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++");
                debug("A arrancar servidor: " + meuendpoint);
                debug("http port: " + meuendpoint.Port);
                debug("tcp port:  " + (meuendpoint.Port + 10000));
                debug("endpoint:  " + meuendpoint.Uri.PathAndQuery.Substring(1));

                Thread.Sleep(100);

                foreach (ServerEndPoint ep in servidores.Values) {
                    AsyncCallNoWait(() => {
                        if (!ep.Execute((x) => x.SrvAlive(meuendpoint.Name)))
                            ep.Status = ServerEndPointStatus.OFFLINE;
                    });
                }

                do {
                    Console.Write("Accao pretendida: ");
                    string cmd = Console.ReadLine();
                    switch (cmd) {
                        case "shutdown":
                            Console.WriteLine("Prima enter para terminar o servidor!");
                            Console.ReadLine();
                            backupServer(nome_servidor);
                            return;

                        case "backup":
                            Console.WriteLine("Saving....");
                            backupServer(nome_servidor);
                            break;

                        case "restore":
                            Console.WriteLine("Loading....");
                            restoreServer(nome_servidor);
                            break;

                        default:
                            Console.WriteLine("Commando invalido");
                            Console.WriteLine("Commandos possiveis: shutdown, backup, restore");
                            break;
                    }
                } while (true);
            }
        }
Ejemplo n.º 11
0
		private void ServerStartupRemoting()
		{
			SoapClientFormatterSinkProvider clientSinkProvider = new SoapClientFormatterSinkProvider();
			IDictionary props = new Hashtable();
			props["typeFilterLevel"] = "Full";

			SoapServerFormatterSinkProvider serverSinkProvider =
				new SoapServerFormatterSinkProvider(props, null);
			ClientIpServerSinkProvider clientIpSinkProvider =
				new ClientIpServerSinkProvider(props, null);
			serverSinkProvider.Next = clientIpSinkProvider;


			props["port"] = ServerPort;
			props["name"] = "ServerChannel";
			HttpChannel chan = new HttpChannel(props, clientSinkProvider, serverSinkProvider);
			string name = chan.ChannelName;
			ChannelServices.RegisterChannel(chan, false);


			if (System.IO.File.Exists(configFile))
				RemotingConfiguration.Configure(configFile, false);
			else
				MessageBox.Show("Missing config file:\r\n" + configFile);

			RemotingConfiguration.RegisterWellKnownServiceType(
				typeof(Allberg.Shooter.WinShooterServer.ClientInterface),
				"WinShooterServer",
				WellKnownObjectMode.Singleton);
		}
        private void Init()
        {
            if (serviceChannel == null)
            {
                //远程抛出错误
                RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
                RemotingConfiguration.CustomErrorsEnabled(false);

                IClientChannelSinkProvider clientProvider;
                IServerChannelSinkProvider serverProvider;

                if (channelType == RemotingChannelType.Tcp)
                {
                    //使用二进制格式化
                    clientProvider = new BinaryClientFormatterSinkProvider();

                    //使用二进制格式化
                    serverProvider = new BinaryServerFormatterSinkProvider();

                    //设置反序列化级别为Full,支持远程处理在所有情况下支持的所有类型
                    (serverProvider as BinaryServerFormatterSinkProvider)
                        .TypeFilterLevel = TypeFilterLevel.Full;
                }
                else
                {
                    //使用SOAP格式化
                    clientProvider = new SoapClientFormatterSinkProvider();

                    //使用SOAP格式化
                    serverProvider = new SoapServerFormatterSinkProvider();

                    //设置反序列化级别为Full,支持远程处理在所有情况下支持的所有类型
                    (serverProvider as SoapServerFormatterSinkProvider)
                        .TypeFilterLevel = TypeFilterLevel.Full;
                }

                string name = AppDomain.CurrentDomain.FriendlyName;

                foreach (var channel in ChannelServices.RegisteredChannels)
                {
                    if (channel.ChannelName == name)
                    {
                        ChannelServices.UnregisterChannel(channel);
                        break;
                    }
                }

                IDictionary props = new Hashtable();
                props["name"] = name;
                props["port"] = serverPort;

                //初始化通道并注册
                if (channelType == RemotingChannelType.Tcp)
                    serviceChannel = new TcpChannel(props, clientProvider, serverProvider);
                else
                    serviceChannel = new HttpChannel(props, clientProvider, serverProvider);

                try
                {
                    ChannelServices.RegisterChannel(serviceChannel, false);
                }
                catch (RemotingException ex)
                {
                    //注册信道出错
                }
            }
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            TMParser parser = new TMParser();
            if (!parser.Parse(args))
            {
                return;
            }

            var serverProv = new SoapServerFormatterSinkProvider { TypeFilterLevel = TypeFilterLevel.Full };

            var clientProv = new SoapClientFormatterSinkProvider();

            IDictionary props = new Hashtable();
            props["port"] = Int32.Parse(parser["p"]);

            var channel = new HttpChannel(props, clientProv, serverProv);
            ChannelServices.RegisterChannel(channel, false);

            RemotingConfiguration.RegisterWellKnownServiceType
                (Type.GetType("MyTM.MyTM")  // full type name
                        , "TM.soap"         // URI
                        , System.Runtime.Remoting.WellKnownObjectMode.Singleton	// instancing mode
                );

            while (true)
            {
                Thread.Sleep(2000);
                TwoPhaseCommit.PrintMessage();
            }
        }