简单Remoting例子(1)
服务器:
 Server
General:
Server
General:
 提供服务的真实类
客户:
提供服务的真实类
客户:
 Server
Server 提供服务的真实类
提供服务的真实类 1 using System;
using System;
2 using System.Runtime.Remoting;
using System.Runtime.Remoting;
3 using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels;
4 using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Tcp;
5 using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Channels.Http;
6 using System.IO;
using System.IO;
7
8 namespace RemotingSamples
namespace RemotingSamples 
9 {
{
10 public class Client
    public class Client
11 {
    {
12 public static void Main(string[] args)
        public static void Main(string[] args)
13 {
        {
14 //使用TCP通道得到远程对象
            //使用TCP通道得到远程对象
15 TcpChannel chan1 = new TcpChannel();
            TcpChannel chan1 = new TcpChannel();
16 ChannelServices.RegisterChannel(chan1);
            ChannelServices.RegisterChannel(chan1);
17 HelloServer obj1 = (HelloServer)Activator.GetObject(
            HelloServer obj1 = (HelloServer)Activator.GetObject(
18 typeof(RemotingSamples.HelloServer),
                typeof(RemotingSamples.HelloServer),
19 "tcp://localhost:8085/SayHello");
                "tcp://localhost:8085/SayHello");
20 if (obj1 == null)
            if (obj1 == null)
21 {
            {
22 System.Console.WriteLine(
                System.Console.WriteLine(
23 "Could not locate TCP server");
                    "Could not locate TCP server");
24 }
            }
25 //使用HTTP通道得到远程对象
            //使用HTTP通道得到远程对象
26 HttpChannel chan2 = new HttpChannel();
            HttpChannel chan2 = new HttpChannel();
27 ChannelServices.RegisterChannel(chan2);
            ChannelServices.RegisterChannel(chan2);
28 HelloServer obj2 = (HelloServer)Activator.GetObject(
            HelloServer obj2 = (HelloServer)Activator.GetObject(
29 typeof(RemotingSamples.HelloServer),
                typeof(RemotingSamples.HelloServer),
30 "http://localhost:8086/SayHello");
                "http://localhost:8086/SayHello");
31 if (obj2 == null)
            if (obj2 == null)
32 {
            {
33 System.Console.WriteLine(
                System.Console.WriteLine(
34 "Could not locate HTTP server");
                    "Could not locate HTTP server");
35 }
            }
36
37 Console.WriteLine(
            Console.WriteLine(
38 "Client1 TCP HelloMethod {0}",
                "Client1 TCP HelloMethod {0}",
39 obj1.HelloMethod("Caveman1"));
                obj1.HelloMethod("Caveman1"));
40 Console.WriteLine(
            Console.WriteLine(
41 "Client2 HTTP HelloMethod {0}",
                "Client2 HTTP HelloMethod {0}",
42 obj2.HelloMethod("Caveman2"));
                obj2.HelloMethod("Caveman2"));
43 Console.ReadLine();
            Console.ReadLine();
44 }
        }
45 /*
/*
46 RemotingConfiguration.Configure(@"C:\Documents and Settings\RenMin\桌面\Remoting\Demo\02-SimpleRemoting\Client\client.exe.config");
            RemotingConfiguration.Configure(@"C:\Documents and Settings\RenMin\桌面\Remoting\Demo\02-SimpleRemoting\Client\client.exe.config");
47 HelloServer obj2 = new HelloServer();
            HelloServer obj2 = new HelloServer();
48 */
*/
49 }
    }
50 }
}
51
 using System;
using System;2
 using System.Runtime.Remoting;
using System.Runtime.Remoting;3
 using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels;4
 using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Tcp;5
 using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Channels.Http;6
 using System.IO;
using System.IO;7

8
 namespace RemotingSamples
namespace RemotingSamples 9
 {
{10
 public class Client
    public class Client11
 {
    {12
 public static void Main(string[] args)
        public static void Main(string[] args)13
 {
        {14
 //使用TCP通道得到远程对象
            //使用TCP通道得到远程对象15
 TcpChannel chan1 = new TcpChannel();
            TcpChannel chan1 = new TcpChannel();16
 ChannelServices.RegisterChannel(chan1);
            ChannelServices.RegisterChannel(chan1);17
 HelloServer obj1 = (HelloServer)Activator.GetObject(
            HelloServer obj1 = (HelloServer)Activator.GetObject(18
 typeof(RemotingSamples.HelloServer),
                typeof(RemotingSamples.HelloServer),19
 "tcp://localhost:8085/SayHello");
                "tcp://localhost:8085/SayHello");20
 if (obj1 == null)
            if (obj1 == null)21
 {
            {22
 System.Console.WriteLine(
                System.Console.WriteLine(23
 "Could not locate TCP server");
                    "Could not locate TCP server");24
 }
            }25
 //使用HTTP通道得到远程对象
            //使用HTTP通道得到远程对象26
 HttpChannel chan2 = new HttpChannel();
            HttpChannel chan2 = new HttpChannel();27
 ChannelServices.RegisterChannel(chan2);
            ChannelServices.RegisterChannel(chan2);28
 HelloServer obj2 = (HelloServer)Activator.GetObject(
            HelloServer obj2 = (HelloServer)Activator.GetObject(29
 typeof(RemotingSamples.HelloServer),
                typeof(RemotingSamples.HelloServer),30
 "http://localhost:8086/SayHello");
                "http://localhost:8086/SayHello");31
 if (obj2 == null)
            if (obj2 == null)32
 {
            {33
 System.Console.WriteLine(
                System.Console.WriteLine(34
 "Could not locate HTTP server");
                    "Could not locate HTTP server");35
 }
            }36

37
 Console.WriteLine(
            Console.WriteLine(38
 "Client1 TCP HelloMethod {0}",
                "Client1 TCP HelloMethod {0}",39
 obj1.HelloMethod("Caveman1"));
                obj1.HelloMethod("Caveman1"));40
 Console.WriteLine(
            Console.WriteLine(41
 "Client2 HTTP HelloMethod {0}",
                "Client2 HTTP HelloMethod {0}",42
 obj2.HelloMethod("Caveman2"));
                obj2.HelloMethod("Caveman2"));43
 Console.ReadLine();
            Console.ReadLine();44
 }
        }45
 /*
/*46
 RemotingConfiguration.Configure(@"C:\Documents and Settings\RenMin\桌面\Remoting\Demo\02-SimpleRemoting\Client\client.exe.config");
            RemotingConfiguration.Configure(@"C:\Documents and Settings\RenMin\桌面\Remoting\Demo\02-SimpleRemoting\Client\client.exe.config");47
 HelloServer obj2 = new HelloServer();
            HelloServer obj2 = new HelloServer();48
 */
*/49
 }
    }50
 }
}51

.jpg) 
  
 
                    
                
 

 
     
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号