.NET Remoting问题,如何测试

sqn1982 2012-11-19 01:19:19
我在学习C#高级编程.NET Remoting的时候,书中一开始有个例子:
①创建一个程序集:RemoteHello.dll,以下为代码:
using System;

namespace Wrox.ProCSharp.Remoting
{
public class Hello: System.MarshalByRefObject
{
public Hello()
{
Console.WriteLine("构造函数启动了!");
}

~Hello()
{
Console.WriteLine("析构函数启动了!");
}

public string Greeting(string name)
{
Console.WriteLine("问候启动了!");
return "你好," + name;
}
}
}


②建立简单的服务器:HelloServer.exe控制台应用程序,引用上面的RemoteHello.dll程序集,以下为代码:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace Wrox.ProCSharp.Remoting
{
class Program
{
static void Main(string[] args)
{
TcpServerChannel channel = new TcpServerChannel(8086);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Hello), "Hi", WellKnownObjectMode.SingleCall);

System.Console.WriteLine("press return to exit");
System.Console.ReadLine();
}
}
}

③建立简单的客户机HelloClient.exe控制台应用程序,引用上面的RemoteHello.dll程序集,以下为代码:
using System;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace Wrox.ProCSharp.Remoting
{
class Program
{
static void Main(string[] args)
{
ChannelServices.RegisterChannel(new TcpClientChannel(), false);

Hello obj = (Hello)Activator.GetObject(typeof(Hello), "tcp://localhost:8086/Hi");

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

for (int i = 0; i < 5; i++)
{
Console.WriteLine(obj.Greeting("你好!"));
}
}
}
}


现在的问题是,三个项目我都做好了,但是该怎么测试效果呢?
比如我改把两个控制台应用程序都放在哪里?先执行哪个后执行哪个才能测试出.Remoting调用的结果?
...全文
68 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hyde100 2012-11-19
  • 打赏
  • 举报
回复
先运行HelloServer.exe,再运行HelloClient.exe就会看到结果了
sqn1982 2012-11-19
  • 打赏
  • 举报
回复
高手在哪里啊?。。。

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧