在用Remoting时遇到的一个问题:一个继承类
[Serializable]
public class MyDataSet: DataSet
{
   //一些简便的方法
}在一个继承 MarshalByRefObject的类的实例中用方法返回MyDataSet实例,如:
public MyDataSet GetItemList()
{
   MyDataSet myDataSet;
   
   //myDataSet的获取
   return myDataSet;
}最后,在客户端调用服务器端的GetItemList时,报错:未找到反序列化 MyDataSet 类型对象的构造函数。什么问题,我要怎么做???

解决方案 »

  1.   

    /// <summary>
    /// 反序列化
    /// </summary>
    /// <param name="info"></param>
    /// <param name="context"></param>
    public EntityData(SerializationInfo info,StreamingContext context)
    {
    DataTable dtTmp;
    DataSet dsTmp,dsTmp1;
    string strSchema; //获取序列化内容
    strSchema= ((string)(info.GetValue("XmlSchema",typeof(string))));
    if ((strSchema != null)) 
    {
    //生成临时 DataSet
    dsTmp= new DataSet();
    dsTmp1= new DataSet();
    dsTmp.ReadXmlSchema(new XmlTextReader(new StringReader(strSchema)));

    //加入表
    for(int i= dsTmp.Tables.Count - 1; i >= 0; i--)
    {
    dtTmp= dsTmp.Tables[i];
    dsTmp.Tables.Remove(dtTmp); dsTmp1.Tables.Add(dtTmp);
    }
    for(int i= dsTmp1.Tables.Count - 1; i >= 0; i--)
    {
    dtTmp= dsTmp1.Tables[i];
    dsTmp1.Tables.Remove(dtTmp); this.Tables.Add(dtTmp);
    } //其它参数
    this.DataSetName= dsTmp.DataSetName;
    this.Prefix= dsTmp.Prefix;
    this.Namespace= dsTmp.Namespace;
    this.Locale= dsTmp.Locale;
    this.CaseSensitive= dsTmp.CaseSensitive;
    this.EnforceConstraints= dsTmp.EnforceConstraints;
    this.Merge(dsTmp, false, System.Data.MissingSchemaAction.Add);
    }
    this.GetSerializationData(info, context);
    }