コード例 #1
0
ファイル: client.cs プロジェクト: ruo2012/samples-1
    public static void Main()
    {
// </Snippet5>
// <Snippet6>
        ChannelServices.RegisterChannel(new TcpChannel());

        RemotingConfiguration.RegisterWellKnownClientType(
            typeof(HelloService),
            "tcp://localhost:8082/HelloServiceApplication/MyUri"
            );

        HelloService service = new HelloService();

// </Snippet6>
// <Snippet7>

        if (service == null)
        {
            Console.WriteLine("Could not locate server.");
            return;
        }


        // Calls the remote method.
        Console.WriteLine();
        Console.WriteLine("Calling remote object");
        Console.WriteLine(service.HelloMethod("Caveman"));
        Console.WriteLine(service.HelloMethod("Spaceman"));
        Console.WriteLine(service.HelloMethod("Client Man"));
        Console.WriteLine("Finished remote object call");
        Console.WriteLine();
    }
コード例 #2
0
    public static void Main()
    {
        try
        {
// <Snippet2>
            IClientChannelSinkProvider mySoapProvider =
                new SoapClientFormatterSinkProvider();
            IClientChannelSinkProvider myClientProvider = new MyClientProvider();
            // Set the custom provider as the next 'IClientChannelSinkProvider' in the sink chain.
            mySoapProvider.Next = myClientProvider;
// </Snippet2>
            TcpChannel myTcpChannel = new TcpChannel(null, mySoapProvider, null);

            ChannelServices.RegisterChannel(myTcpChannel);

            RemotingConfiguration.RegisterWellKnownClientType(typeof(HelloService),
                                                              "tcp://localhost:8082/HelloServiceApplication/MyUri");

            HelloService myService = new HelloService();

            Console.WriteLine(myService.HelloMethod("Welcome to .Net"));
        }
        catch (Exception ex)
        {
            Console.WriteLine("The following  exception is raised at client side :" + ex.Message);
        }
    }
コード例 #3
0
    static void Main()
    {
        // Register a channel.
        TcpChannel myChannel = new TcpChannel();

        ChannelServices.RegisterChannel(myChannel);
        RemotingConfiguration.RegisterActivatedClientType(
            typeof(HelloService), "tcp://localhost:8085/");

        // Get the remote object.
        HelloService myService = new HelloService();

        // Get a sponsor for renewal of time.
        ClientSponsor mySponsor = new ClientSponsor();

        // Register the service with sponsor.
        mySponsor.Register(myService);

        // Set renewaltime.
        mySponsor.RenewalTime = TimeSpan.FromMinutes(2);

        // Renew the lease.
        ILease   myLease = (ILease)mySponsor.InitializeLifetimeService();
        TimeSpan myTime  = mySponsor.Renewal(myLease);

        Console.WriteLine("Renewed time in minutes is " + myTime.Minutes.ToString());

        // Call the remote method.
        Console.WriteLine(myService.HelloMethod("World"));

        // Unregister the channel.
        mySponsor.Unregister(myService);
        mySponsor.Close();
    }
コード例 #4
0
 public static void Main()
 {
     try
     {
         IClientChannelSinkProvider myFormatterProvider =
             new MyClientFormatterProvider();
         myFormatterProvider.Next =
             new SoapClientFormatterSinkProvider();
         TcpChannel myTcpChannel = new TcpChannel(null,
                                                  myFormatterProvider, null);
         ChannelServices.RegisterChannel(myTcpChannel, false);
         RemotingConfiguration.RegisterWellKnownClientType(typeof(HelloService),
                                                           "tcp://localhost:8082/HelloServiceApplication/MyUri");
         HelloService myService = new HelloService();
         Console.WriteLine(myService.HelloMethod("Welcome to .Net"));
     }
     catch (Exception ex)
     {
         Console.WriteLine("The following exception is raised at client side" + ex.Message);
     }
 }