我用Activator.GetObject获得了一个服务器端对象
但是在调用其函数时出现RemotingException:Attempted to call a method declared on type 'ServerApplication.ServerInitor' on an object which exposes 'ServerApplication.UserMgr'.客户端代码:public void Logon()
{
ServerApplication.ServerInitor server =
(ServerApplication.ServerInitor)Activator.GetObject(typeof(ServerApplication.ServerInitor), "tcp://192.168.0.4:2739/chat");
         server.Log_on("a"); //该函数报异常
}
服务器端代码:
public class ServerInitor: MarshalByRefObject
{
  private UserMgr userManager;
   
   //中间代码略  public Guid Log_on(string nick)
  {
          return userManager.Logon(nick);
  }  public void Log_off(Guid guid)
  {
  userManager.Logoff(guid);
  }  public void Say(String guid, String content)
  {
  userManager.Say(guid, content);
  }

解决方案 »

  1.   

    RemoteObject 没调用对把?
    ServerApplication.ServerInitor server =
    (ServerApplication.ServerInitor)Activator.GetObject(typeof(ServerApplication.ServerInitor), "tcp://192.168.0.4:2739/ServerInitor.Rem");
      

  2.   


    //仅供参考
    /*  --------   server --------   */
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections;
    using System.Runtime.Remoting;
    using System.Runtime.Remoting.Channels;
    using System.Runtime.Remoting.Services;
    using System.Runtime.Remoting.Channels.Tcp;
    using Test04_Demo;try
    {
       IDictionary ports = new Hashtable();
       ports["port"] = 8100;
       BinaryClientFormatterSinkProvider cs = new BinaryClientFormatterSinkProvider();
       BinaryServerFormatterSinkProvider ss = new BinaryServerFormatterSinkProvider();
       //TcpChannel channel = new TcpChannel(ports, cs, ss);
       channel = new TcpChannel(ports, cs, ss);
       ChannelServices.RegisterChannel(channel, false);
       Demo demo = new Demo();
       RemotingServices.Marshal(demo, "test04_demo.soap");
       lblOne.Text = "好极了,1号服务启动成功!";
    }
    catch
    {
       lblOne.Text = "因网络或其他故障,未能成功启动服务";
    }/* -------- client ----------*/
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Test04_Demo;try
    {
      demo = (Demo)Activator.GetObject(typeof(Demo), "tcp://localhost:8100/test04_demo.soap");
      if (demo != null)
      {
         lblInfo.Text = "恭喜,已经连接成功";
      }
    }
    catch
    {
      lblInfo.Text = "抱歉,因故未能连接上";
    }
      

  3.   

    RemotingServices.Marshal(demo, "test04_demo.soap");好! 就是这句话解决了大问题!
    OK,散分