有三个项目,分解为:客户端,服务端,接口;
客户站的代码:
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
TcpChannel tcp=new TcpChannel();
ChannelServices.RegisterChannel(tcp);
Itestinterface obj=(Itestinterface)Activator.GetObject(typeof(Itestinterface),"tcp://192.168.0.211:8080/vcool");
if(obj!=null)
{
Console.WriteLine(obj.ToString());
obj.writeText();
string str=Console.ReadLine();
obj.writeParm(str);
Console.ReadLine();
}
}
服务器端:
有二部分:一个实现接口,另一个就是服务端运行
Itestinterface为接口
/// <summary>
/// testServer 的摘要说明。
/// </summary>
public class testServer:MarshalByRefObject,Itestinterface
{
public testServer()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void writeText()
{
Console.WriteLine("hello world!");
}
public void writeParm(string str)
{
Console.WriteLine(" your writting is: " +str);
}
}
服务运行:
TcpChannel tcp=new TcpChannel(8080);
ChannelServices.RegisterChannel(tcp);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(testServer),"vcool",WellKnownObjectMode.Singleton);
Console.ReadLine();
接口
/// <summary>
/// testinterface 的摘要说明。
/// </summary>
public interface Itestinterface
{
void writeText();
void writeParm(string str);
}
浙公网安备 33010602011771号