citymeteor(流星) :问题是我不知道该怎么解决啊!!!

解决方案 »

  1.   

    信道 tcp 已注册,同一个信道只能注册一次。跟一下,看看你注册了几次?或是多次调用注册过程?参考的对象种类不支持尝试的操作。”看看代码才知道。
      

  2.   

    citymeteor(流星) :
    谢谢!!!Server.CS:
    [STAThread]
    static void Main(string[] args)
    {
    //
    // TODO: 在此处添加代码以启动应用程序
    //
    TcpServerChannel foChannel = new TcpServerChannel(8086);
    ShowChanelProperties(foChannel);
    ChannelServices.RegisterChannel(foChannel);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteDLL.RemoteObject ),"RemoteObject",WellKnownObjectMode.SingleCall);
    Console.WriteLine("按任意键退出");
    Console.ReadLine();
    ChannelServices.UnregisterChannel(foChannel); }share.cs:public class CDocument : System.MarshalByRefObject
    {
    private int iDocID;
    private string sDocNumber; public int DocID
    {
    get
    {
    return iDocID;
    }
    set
    {
    iDocID = value;
    }
    }
    public string DocNumber
    {
    get
    {
    return sDocNumber;
    }
    set
    {
    sDocNumber = value;
    }
    }
    public CDocument()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    iDocID = 0;
    sDocNumber = "";
    }
    public void SetValue(int fiDocID,string fsDocNumber)
    {
    iDocID = fiDocID;
    sDocNumber = fsDocNumber;
    }
    }
    public class RemoteObject : System.MarshalByRefObject
    {
    public RemoteObject()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    Console.WriteLine("实例化RemoteObject对象");
    } ~RemoteObject()
    {
    Console.WriteLine("清除RemoteObject对象");
    } public string ShowMsg(string fsMsg)
    {
    return "Hello:" + fsMsg;
    }
    public CDocument SetDocValue(CDocument foDoc)
    {
    foDoc.SetValue(1234,"cuibw");
    return foDoc;
    }
    }
    client.cs:[STAThread]
    static void Main(string[] args)
    {
    //
    // TODO: 在此处添加代码以启动应用程序
    //
    TcpChannel chan = new TcpChannel();
    ChannelServices.RegisterChannel(chan);
    RemoteDLL.CDocument foDoc = new RemoteDLL.CDocument();
    RemoteDLL.RemoteObject foRemote = (RemoteDLL.RemoteObject)Activator.GetObject(typeof(RemoteDLL.RemoteObject), "tcp://localhost:8086/RemoteObject");
    if(foRemote == null && foDoc == null)
    {
    Console.WriteLine("未找到服务器");
    }
    foRemote.SetDocValue(foDoc);
    }就在最后一句报错