C# .NET Remoting 简单应用示例
2008-03-24 20:17
981 查看
这个是Remoting中的HelloWorld
using System;
namespace zhl
...{
public class Person:MarshalByRefObject
...{
private string m_name;
public string Name
...{
get
...{
return this.m_name;
}
set
...{
this.m_name = value;
}
}
public string SayHello()
...{
Console.WriteLine("Hello,my name is {0}",m_name);
return "Hi," + m_name;
}
}
}
Server:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace zhl
...{
class Server
...{
static void Main(string[] args)
...{
TcpChannel channel = new TcpChannel(8000);
ChannelServices.RegisterChannel(channel,true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Person), "PersonUrl", WellKnownObjectMode.Singleton);
Console.WriteLine("Please press enter to exit");
Console.ReadLine();
}
}
}
Client:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace zhl
...{
class Client
...{
static void Main(string[] args)
...{
TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel,true);
Person person = (Person)Activator.GetObject(typeof(Person), "tcp://localhost:8000/PersonUrl");
person.Name = "zhao hongliang";
string reply = person.SayHello();
Console.WriteLine(reply);
Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}
}
}
using System;
namespace zhl
...{
public class Person:MarshalByRefObject
...{
private string m_name;
public string Name
...{
get
...{
return this.m_name;
}
set
...{
this.m_name = value;
}
}
public string SayHello()
...{
Console.WriteLine("Hello,my name is {0}",m_name);
return "Hi," + m_name;
}
}
}
Server:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace zhl
...{
class Server
...{
static void Main(string[] args)
...{
TcpChannel channel = new TcpChannel(8000);
ChannelServices.RegisterChannel(channel,true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Person), "PersonUrl", WellKnownObjectMode.Singleton);
Console.WriteLine("Please press enter to exit");
Console.ReadLine();
}
}
}
Client:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace zhl
...{
class Client
...{
static void Main(string[] args)
...{
TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel,true);
Person person = (Person)Activator.GetObject(typeof(Person), "tcp://localhost:8000/PersonUrl");
person.Name = "zhao hongliang";
string reply = person.SayHello();
Console.WriteLine(reply);
Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}
}
}
相关文章推荐
- c# .net windows消息队列简单应用示例
- c# .net windows消息队列简单应用示例
- C#.net,remoting的简单应用实例
- C# .net Remoting最简单的例子
- Asp.Net 3.5 应用Linq的例子1(C#)以及Web.Config示例
- VS.NET 2005 + VSS6.0简单应用示例
- 在C#代码中应用Log4Net(一)简单使用Log4Net
- 在C#代码中应用Log4Net(一)简单使用Log4Net
- .netRemoting 简单示例
- asp.net(c#)中使用反射动态加载dll简单示例
- Asp.net 在网页编写C#代码示例-- 一个简单的web MsSql 命令执行环境
- .NET Remoting 最简单示例
- WinForm(C#) DataGridView简单应用示例
- 在C#代码中应用Log4Net(一)简单使用Log4Net
- 在C#代码中应用Log4Net(一)简单使用Log4Net
- 【原创】 ASP.NET C#反射简单实例应用
- 贴下百度博客自动加好友的简单代码示例!!(c#.net实现)
- C# .Net Remoting示例
- 在C#代码中应用Log4Net(一)简单使用Log4Net
- 在C#代码中应用Log4Net(一)简单使用Log4Net