加了,但是在Remoting的客户端说找不到反序列化方法,类是这样定义的: using System; using System.Collections.Generic; using System.Text; using System.Data;namespace Microsoft.Samples.SharedInterface { [Serializable] public class BusinessEntity : DataSet { public BusinessEntity() { DataTable dt = new DataTable(); dt.Columns.Clear(); dt.Columns.Add(new DataColumn("CustomerName", typeof(string))); dt.Columns.Add(new DataColumn("CustomerBirthday", typeof(DateTime))); DataRow dr = dt.NewRow(); dr[0] = "bvw"; dr[1] = DateTime.Now; dt.Rows.Add(dr); this.Tables.Add(dt); } public string CustomerName { get { return this.Tables[0].Rows[0][0].ToString(); } } public DateTime CustomerBirthday { get { return (DateTime)this.Tables[0].Rows[0][1]; } } } }
客户端是这样用的: ISharedInterface remoteObject = (ISharedInterface)Activator.GetObject(typeof(ISharedInterface), "tcp://localhost:8080/server.rem"); BusinessEntity entity = remoteObject.GetEntity(); Console.WriteLine("Customer's Name is: {0}, birthday is: {1}", entity.CustomerName, entity.CustomerBirthday.ToLongDateString());另外用到了一个接口IShareInterface: BusinessEntity GetEntity(); 其实现类中的方法: public class ImplementationClass : MarshalByRefObject, ISharedInterface { public BusinessEntity GetEntity() { return new BusinessEntity(); } } 错误如下: The constructor to deserialize an object of type 'Microsoft.Samples.SharedInterface.BusinessEntity' was not found.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;namespace Microsoft.Samples.SharedInterface
{
[Serializable]
public class BusinessEntity : DataSet
{
public BusinessEntity()
{
DataTable dt = new DataTable();
dt.Columns.Clear();
dt.Columns.Add(new DataColumn("CustomerName", typeof(string)));
dt.Columns.Add(new DataColumn("CustomerBirthday", typeof(DateTime)));
DataRow dr = dt.NewRow();
dr[0] = "bvw";
dr[1] = DateTime.Now;
dt.Rows.Add(dr);
this.Tables.Add(dt);
}
public string CustomerName
{
get { return this.Tables[0].Rows[0][0].ToString(); }
} public DateTime CustomerBirthday
{
get { return (DateTime)this.Tables[0].Rows[0][1]; }
}
}
}
ISharedInterface remoteObject = (ISharedInterface)Activator.GetObject(typeof(ISharedInterface), "tcp://localhost:8080/server.rem");
BusinessEntity entity = remoteObject.GetEntity();
Console.WriteLine("Customer's Name is: {0}, birthday is: {1}", entity.CustomerName, entity.CustomerBirthday.ToLongDateString());另外用到了一个接口IShareInterface:
BusinessEntity GetEntity();
其实现类中的方法:
public class ImplementationClass : MarshalByRefObject, ISharedInterface
{
public BusinessEntity GetEntity()
{
return new BusinessEntity();
}
}
错误如下:
The constructor to deserialize an object of type 'Microsoft.Samples.SharedInterface.BusinessEntity' was not found.
DataSet本身是从MarshalByValObject继承的,也应该是可以的啊,而且,在WebService中使用同样的类没有问题,只是在Remoting 中才出问题。
protected BusinessEntity(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
{}就可以了