首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET Framework >

.NET Remoting有关问题,怎么测试

2012-12-20 
.NET Remoting问题,如何测试我在学习C#高级编程.NET Remoting的时候,书中一开始有个例子:①创建一个程序集:

.NET Remoting问题,如何测试
我在学习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调用的结果?
[最优解释]
先运行HelloServer.exe,再运行HelloClient.exe就会看到结果了
[其他解释]
高手在哪里啊?。。。

热点排行