コード例 #1
0
        public static void Main()
        {
            string myChannelURL = "tcp://" + Dns.Resolve(Dns.GetHostName())
                                  .AddressList[0] + ":8085/SayHello";
            ListDictionary myListDictionary = new ListDictionary();

            myListDictionary.Add("port", 8086);
            TcpChannel myCustomChannel = new TcpChannel(myListDictionary,
                                                        new SoapClientFormatterSinkProvider(),
                                                        new SoapServerFormatterSinkProvider());

            ChannelServices.RegisterChannel(myCustomChannel);
            try
            {
                HelloServer myHelloServer = (HelloServer)Activator.GetObject
                                                (typeof(RemotingSamples.HelloServer), myChannelURL);
                if (myHelloServer == null)
                {
                    Console.WriteLine("Could not locate server.");
                }
                else
                {
                    Console.WriteLine(myHelloServer.HelloMethod("Caveman"));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Message : " + e.Message);
            }
        }
コード例 #2
0
        public static void Main()
        {
            try
            {
                TcpChannel myTcpChannel = new TcpChannel(8084);
                ChannelServices.RegisterChannel(myTcpChannel);
                HelloServer myHelloServer = (HelloServer)Activator.GetObject(typeof
                                                                             (RemotingSamples.HelloServer), "tcp://localhost:8080/SayHello");
                if (myHelloServer == null)
                {
                    System.Console.WriteLine("Could not locate server");
                }
                else
                {
// <Snippet4>
                    string[] myURLArray = ChannelServices.GetUrlsForObject(myHelloServer);
                    Console.WriteLine("Number of URLs for the specified Object: "
                                      + myURLArray.Length);
                    for (int iIndex = 0; iIndex < myURLArray.Length; iIndex++)
                    {
                        Console.WriteLine("URL: " + myURLArray[iIndex]);
                    }
// </Snippet4>
                    Console.WriteLine(myHelloServer.HelloMethod("Caveman"));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught!!!");
                Console.WriteLine("The source of exception: " + e.Source);
                Console.WriteLine("The Message of exception: " + e.Message);
            }
        }
コード例 #3
0
 public void RunMe()
 {
     if (Thread.CurrentThread == thread1)
     {
         Console.WriteLine("Ceci est le thread un");
         HelloServer obj = (HelloServer)Activator.GetObject(typeof(HelloServer), "tcp://localhost:8089/SayHello");
         for (int i = 0; i < 100; i++)
         {
             Console.WriteLine(obj.CountMe() + " -  partir du thread 1 ");
             Thread.Sleep(0);
         }
     }
     else if (Thread.CurrentThread == thread2)
     {
         // TcpChannel chan = new TcpChannel();
         //ChannelServices.RegisterChannel(chan, true);
         Console.WriteLine("Ceci est le thread deux");
         HelloServer obj = (HelloServer)Activator.GetObject(typeof(HelloServer), "tcp://localhost:8089/SayHello");
         for (int i = 0; i < 100; i++)
         {
             Console.WriteLine(obj.CountMe() + " -  partir du thread 2 ");
             Thread.Sleep(0);
         }
     }
 }
コード例 #4
0
        public static void Main()
        {
            ListDictionary myProperties = new ListDictionary();

            myProperties.Add("port", 8085);
            myProperties.Add("name", "MyHttpChannel");
// <Snippet1>
            HttpChannel myClientChannel = new HttpChannel(myProperties,
                                                          new SoapClientFormatterSinkProvider(),
                                                          new SoapServerFormatterSinkProvider());

            ChannelServices.RegisterChannel(myClientChannel);
            // Get the registered channel.
            Console.WriteLine("Channel Name : " + ChannelServices.GetChannel(
                                  myClientChannel.ChannelName).ChannelName);
            Console.WriteLine("Channel Priorty : " + ChannelServices.GetChannel(
                                  myClientChannel.ChannelName).ChannelPriority);
// </Snippet1>
            HelloServer myProxy = (HelloServer)Activator.GetObject(typeof(
                                                                       RemotingSamples.HelloServer), "http://localhost:8086/SayHello");
// <Snippet2>
            // Get an IDictionary of properties for a given proxy.
            IDictionary myDictionary = ChannelServices.
                                       GetChannelSinkProperties(myProxy);
            ICollection myKeysCollection = myDictionary.Keys;

            object[]    myKeysArray        = new object[myKeysCollection.Count];
            ICollection myValuesCollection = myDictionary.Values;

            object[] myValuesArray = new object[myValuesCollection.Count];
            myKeysCollection.CopyTo(myKeysArray, 0);
            myValuesCollection.CopyTo(myValuesArray, 0);
            for (int iIndex = 0; iIndex < myKeysArray.Length; iIndex++)
            {
                Console.WriteLine("Property Name : " + myKeysArray[iIndex] +
                                  " value : " + myValuesArray[iIndex]);
            }
// </Snippet2>
            if (myProxy == null)
            {
                System.Console.WriteLine("Could not locate server");
            }
            else
            {
                Console.WriteLine(myProxy.HelloMethod("Caveman"));
            }
        }
コード例 #5
0
ファイル: Client.cs プロジェクト: Theo0/M1S2
        public static int Main(string[] args)
        {
            TcpChannel chan = new TcpChannel(8086);

            ChannelServices.RegisterChannel(chan, true);
            ForwardMe   param = new ForwardMe();
            HelloServer obj   = (HelloServer)Activator.GetObject(typeof(RemotingSamples.HelloServer), "tcp://localhost:8085/SayHello");

            if (obj == null)
            {
                System.Console.WriteLine("Impossible de trouver le serveur");
            }
            else
            {
                Console.WriteLine(obj.HelloMethod("Homme des cavernes", param));
            }
            Console.Read();
            return(0);
        }
コード例 #6
0
ファイル: Client.cs プロジェクト: Theo0/M1S2
 public void RunMe()
 {
     if (Thread.CurrentThread == thread1)
     {
         Console.WriteLine("Ceci est le thread un");
         HelloServer obj = (HelloServer)Activator.GetObject(typeof(HelloServer), "tcp://localhost:8089/SayHello");
         for (int i = 0; i < 100; i++)
         {
             Console.WriteLine(obj.CountMe() + " depuis le thread 1 ");
             Thread.Sleep(0);
         }
     }
     else if (Thread.CurrentThread == thread2)
     {
         Console.WriteLine("Ceci est le thread deux");
         HelloServer obj = (HelloServer)Activator.GetObject(typeof(HelloServer), "tcp://localhost:8089/SayHello");
         for (int i = 0; i < 100; i++)
         {
             Console.WriteLine(obj.CountMe() + " depuis le thread 2 ");
             Thread.Sleep(0);
         }
     }
 }
コード例 #7
0
        public static int Main(string[] args)
        {
            TcpChannel chan = new TcpChannel(8086);

            Console.WriteLine("channel créé");
            ChannelServices.RegisterChannel(chan, true);
            Console.WriteLine("channel enregistré");
            Console.ReadLine();
            ForwardMe param = new ForwardMe(); // objet créé chez le client
            // ligne suivante, on va chercher un proxy sur le HelloServer publié chez le serveur sur le port 8085, nommé SayHello
            HelloServer obj = (HelloServer)Activator.GetObject(typeof(RemotingSamples.HelloServer), "tcp://localhost:8085/SayHello");

            if (obj == null)
            {
                System.Console.WriteLine("Impossible de trouver le serveur");
            }
            // ligne suivante, on passe en paramètre le ForwardMe local au serveur
            else
            {
                Console.WriteLine(obj.HelloMethod("Homme des cavernes", param));
            }
            Console.Read();
            return(0);
        }