예제 #1
0
        public void Run()
        {
            AllocConsole();


            // Create the channel.
            TcpChannel clientChannel = new TcpChannel();


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

            // Register as client for remote object.
            WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry(
                typeof(ConsoleLoggerProxy), "tcp://localhost:9090/LoggerProxy.rem");

            RemotingConfiguration.RegisterWellKnownClientType(remoteType);

            // Create a message sink.
            string objectUri;

            System.Runtime.Remoting.Messaging.IMessageSink messageSink =
                clientChannel.CreateMessageSink(
                    "tcp://localhost:" + TcpController.Port + "/LoggerProxy.rem", null,
                    out objectUri);
            Console.WriteLine("The URI of the message sink is {0}.",
                              objectUri);
            if (messageSink != null)
            {
                Console.WriteLine("The type of the message sink is {0}.",
                                  messageSink.GetType().ToString());
            }

            // Create an instance of the remote object.
            ConsoleLoggerProxy service = new ConsoleLoggerProxy();

            // Invoke a method on the remote object.
            Console.WriteLine("The client is invoking the remote object.");
            Console.WriteLine("The remote object has been called {0} times.",
                              service.GetCount());

            while (true)
            {
                while (service.Count > 0)
                {
                    Console.WriteLine(service.Dequeue());
                }
            }
        }
예제 #2
0
파일: client.cs 프로젝트: zhimaqiao51/docs
    public static void Main(string[] args)
    {
        //<snippet11>
        // Create the channel.
        TcpChannel clientChannel = new TcpChannel();

        //</snippet11>

        // Register the channel.
        ChannelServices.RegisterChannel(clientChannel, false);

        // Register as client for remote object.
        WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry(
            typeof(RemoteObject), "tcp://localhost:9090/RemoteObject.rem");

        RemotingConfiguration.RegisterWellKnownClientType(remoteType);

        //<snippet12>
        // Create a message sink.
        string objectUri;

        System.Runtime.Remoting.Messaging.IMessageSink messageSink =
            clientChannel.CreateMessageSink(
                "tcp://localhost:9090/RemoteObject.rem", null,
                out objectUri);
        Console.WriteLine("The URI of the message sink is {0}.",
                          objectUri);
        if (messageSink != null)
        {
            Console.WriteLine("The type of the message sink is {0}.",
                              messageSink.GetType().ToString());
        }
        //</snippet12>

        // Create an instance of the remote object.
        RemoteObject service = new RemoteObject();

        // Invoke a method on the remote object.
        Console.WriteLine("The client is invoking the remote object.");
        Console.WriteLine("The remote object has been called {0} times.",
                          service.GetCount());
    }
예제 #3
0
        public int Connect()
        {
            try
            {
                TcpChannel channel = new TcpChannel();
                ChannelServices.RegisterChannel(channel, false);
                WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry(typeof(PuppetServices), puppetMasterUrl);
                RemotingConfiguration.RegisterWellKnownClientType(remoteType);

                string objectUri;
                System.Runtime.Remoting.Messaging.IMessageSink messageSink = channel.CreateMessageSink(puppetMasterUrl, null, out objectUri);

                services = new PuppetServices();
                return(0);
            }
            catch (RemotingException e)
            {
                Console.WriteLine(e.StackTrace);
                return(-1);
            }
        }