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);
            }
        }
        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 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"));
            }
        }
示例#4
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);
        }
示例#5
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);
        }