我创建了了一个书上的一个REMOTE应用的例子,如下:
//远程对象类定义
using System;
using System.Runtime.Serialization;namespace RemoteHello
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
[SerializableAttribute]
public class Hello
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>

public Hello()
{
Console.WriteLine("Constructor called!");
} ~Hello()
{
Console.WriteLine("Destructor called!");
} public string Greeting(string name)
{
Console.WriteLine("Gretting Called!");
return "Hello,"+name;
}
}
}
//客户端
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Http;
using RemoteHello;namespace HelloClient
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class HelloClient
{

/// <summary>
/// 应用程序的主入口点。
/// </summary>
string test="";

static void Main(string[] args)
{
System.Runtime.Remoting.Channels.Tcp.TcpClientChannel channel=new System.Runtime.Remoting.Channels.Tcp.TcpClientChannel();
System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel);
try

Hello hello=(RemoteHello.Hello)Activator.GetObject(typeof(RemoteHello.Hello),"tcp://localhost:8086/Hi"); if(hello==null)
{
Console.WriteLine("Can not locate server!");
return;
}
for(int i=0;i<5;i++)
{
Console.WriteLine(hello.Greeting("LEE   "+i.ToString()));
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}

}
}
}//服务端
using System;
using System.Runtime;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Tcp;
using RemoteHello;namespace RemoteServer
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class RemoteServer
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
System.Runtime.Remoting.Channels.Tcp.TcpServerChannel chanel=new TcpServerChannel(8086);

System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chanel);
System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteHello.Hello),"Hi",
System.Runtime.Remoting.WellKnownObjectMode.SingleCall);   Console.WriteLine("Hit to exit!");
System.Console.ReadLine();
}
}
}//结束执行结果如下:
    服务端运行以后,信道都已经建立起来了,我用命令窗口
NETSTAT -A 看了也没问题   但客户端运行到
   Hello hello=(RemoteHello.Hello)Activator.GetObject(typeof(RemoteHello.Hello),"tcp://localhost:8086/Hi"); 发生异常: {"试图创建未绑定类型的代理。" },不知道是什么原因,
请高手指点!感激不胜!

解决方案 »

  1.   

    楼主:你的远程对象类一定要继承于MarshalByRefObject类,否则是不行地,要不然就自己序列化一下
      

  2.   


    楼上没错。public class Hello : System.MarshalByRefObject
    {
      ...
    }
      

  3.   

    谈谈.NET Remoting!!1.客户端调用Remoting对象,最好在App层的App.Config文件进行配置。
    2.服务器端配置对象如你所写的那样,不用在配置文件里进行配置,因为这样会带来,部分对象占用内存资源,不释放的问题。
    3.调用Remoting对象,最好用一个RemotingProxy层来做代理\....
      

  4.   

    我把你的代码拷贝了,然后加入对MarshalByRefObject的继承,运行ok
    请楼主以后别忘了,做remoting的时候远程对象类一定要继承于这个类,否则就需要自己做序列化工作