⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remoting进行远程通迅.txt

📁 c#的知识类库
💻 TXT
字号:
1.建立一个类库项目:P1
a.类继承于System.MarshalByRefObject
b.定义要公有访问的类A1
2.建立一个服务器项目
a.增加System.Runtime.Remototing和类库项目的引用
b.增加引用:
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp; 
using P1;
c.启动服务
TcpServerChannel channel=new TcpServerChannel(8086);
ChannelServices.RegisterChannel(channel);//注册服务器通道
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Hello),"Hi",WellKnownObjectMode.SingleCall);//注册远程服务对象类型
System.Console.WriteLine("hit to exit");
System.Console.ReadLine(); //等待
3.建立一个客户端项目
a.增加System.Runtime.Remototing和类库项目的引用
b.增加引用:
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp; 
using P1;
c.调用服务
ChannelServices.RegisterChannel(new TcpClientChannel());//注册客户通道
Hello obj=(Hello)Activator.GetObject(typeof(Hello),"tcp://localhost:8086/Hi");//使用透明代理与服务器通信
if(obj==null)//检查通信是否成功
{
	Console.WriteLine("Can not locate server!");
	return;
}
for(int i=0;i<5;i++)//调用服务器上提供的函数
{
Console.WriteLine(obj.Greeting("glf"));
}
Console.WriteLine("hit to exit");
Console.ReadLine();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -