我在服务器端注册一个继承于MarshalByRefObject的类型A,也就是说类型A的对象是按引用传递的,
类型A有一个方法B,我现在远程调用方法B,方法B返回的是一个string数组(string[]),可是我在客户端发现返回的是null,实际上方法B返回的不是空值,请问在.net remoting中如何返回一个数组,让它按值传递?谢谢!

解决方案 »

  1.   

    应该是你代码的问题吧,如果是服务器端的代码,你怎么调试到客户端了呢?
    在remoting中数组我没传递过,但是NameValueCollection我倒是用过
    也是一个集合,每个元素由键值对组成,感觉上有点象哈西表,不过所有的
    键值对都是string型的,理论上来说,应该也是属于数组 的
      

  2.   

    应该是你的代码问题,我做过DataTable型的,没有问题。
      

  3.   

    服务器端:
    System.Runtime.Remoting.Channels.Http.HttpChannel hc = new System.Runtime.Remoting.Channels.Http.HttpChannel(9000);
    System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(hc); System.Runtime.Remoting.RemotingConfiguration.ApplicationName = "SC";
    System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(System.RemotingClass),"DirsAndFiles",System.Runtime.Remoting.WellKnownObjectMode.SingleCall); System.Console.WriteLine("服务已启动......");
    System.Console.ReadLine();
      

  4.   

    客户端:
           string strPath = "http://localhost:9000/sc/DirsAndFiles";//URL  System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownClientType(typeof(System.RemotingClass),strPath);//配置 RemotingClass rc = new RemotingClass();
    rc.Path = "c:\\"; System.Collections.ArrayList al = rc.FilesAndFolders(); this.listBox1.Items.Clear();//加到listbox控件中
    for(int i = 0;i<al.Count;i++)
    {
    this.listBox1.Items.Add((string)al[i]);
    }
      

  5.   

    类:
       public class RemotingClass:System.MarshalByRefObject
    {
    private string strPath = "";//存放要获取文件的路径 public RemotingClass()//构造函数
    {

    } public string Path //属性
    {
    get
    {
    return this.strPath;
    }
    set
    {
    strPath = value;
    }
    }//在客户端得到的是null
    public System.Collections.ArrayList FilesAndFolders()//获取某文件夹下的所有文件名
    {
    if(this.strPath != "")
    {
    if(System.IO.Directory.Exists(strPath) == true)
    {
    System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(strPath);
    System.IO.FileInfo[] fis = di.GetFiles(); al = new System.Collections.ArrayList(); for(int i = 0;i<fis.Length;i++)
    {
    al.Add(fis[i].Name);
    } return al;
    }
    else
    {
    return al;
    }
    }
    else
    {
    return al;
    }
    }
    private System.Collections.ArrayList al = null;
    }