使用Vs2005中:ms-help://MS.VSCC.v80/MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxsamples/html/31db1897-b551-42e6-bd53-0852a68adc08.htm
例子时,我直接运行此例子,一切正常,得到了正确的结果。
我在ISharedInterface项目中增加了一个BusinessEntity类,此类从DataSet继承。只是简单的定义了一个DataSet代码如下:
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.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.Clear();
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]; }
}
}
}在ISharedIterface接口和ImplementionClass类中增加了下个GetEntity()的方法:
public BusinessEntity GetEntity()
{
return new BusinessEntity();
}
我在Client类加增加了下面的代码:
BusinessEntity entity = remoteObject.GetEntity();
Console.WriteLine("Customer's Name is: {0}, birthday is: {1}", entity.CustomerName, entity.CustomerBirthday.ToLongDateString());
Console.WriteLine("Press ENTER to exit...");
Console.ReadLine();
但是报出了这样的错误:
The constructor to deserialize an object of type 'Microsoft.Samples.SharedInterface.BusinessEntity' was not found.但如果我在Client类里增加一个引用ImplementionClass的引用:using Microsoft.Samples.Implementation;
然后在增加如下代码:
ImplementationClass obj = new ImplementationClass();
BusinessEntity directEntity = obj.GetEntity();
Console.WriteLine("Customer's Name is: {0}, birthday is: {1}", directEntity.CustomerName, directEntity.CustomerBirthday.ToLongDateString());
Console.WriteLine("Press ENTER to exit...");
则能返回下确结果。请高帮忙!
例子时,我直接运行此例子,一切正常,得到了正确的结果。
我在ISharedInterface项目中增加了一个BusinessEntity类,此类从DataSet继承。只是简单的定义了一个DataSet代码如下:
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.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.Clear();
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]; }
}
}
}在ISharedIterface接口和ImplementionClass类中增加了下个GetEntity()的方法:
public BusinessEntity GetEntity()
{
return new BusinessEntity();
}
我在Client类加增加了下面的代码:
BusinessEntity entity = remoteObject.GetEntity();
Console.WriteLine("Customer's Name is: {0}, birthday is: {1}", entity.CustomerName, entity.CustomerBirthday.ToLongDateString());
Console.WriteLine("Press ENTER to exit...");
Console.ReadLine();
但是报出了这样的错误:
The constructor to deserialize an object of type 'Microsoft.Samples.SharedInterface.BusinessEntity' was not found.但如果我在Client类里增加一个引用ImplementionClass的引用:using Microsoft.Samples.Implementation;
然后在增加如下代码:
ImplementationClass obj = new ImplementationClass();
BusinessEntity directEntity = obj.GetEntity();
Console.WriteLine("Customer's Name is: {0}, birthday is: {1}", directEntity.CustomerName, directEntity.CustomerBirthday.ToLongDateString());
Console.WriteLine("Press ENTER to exit...");
则能返回下确结果。请高帮忙!
解决方案 »
- C#连接读取Acess数据库的中文字段名(列名)的问题。。菜鸟真心求教
- 这几个函数怎么用的?
- 关于AES加解密,在线等待,另有高分相赠!!
- 怎样在gridview实现模板列单选checkbox?
- 奇怪的 存储过程????--在线等
- 发布程序的问题
- 使用了未赋值的变量"language"怎么回事?
- 继承类有没有办法实现父类private和protected权限字段的深度复制?
- 请教C#高手
- 怎么用将数据库中的数据输出成SqlDataReader或写如其他的SqlDataReader?
- 设计时序列化问题,非.net标准类,反序列化时类型转换出错
- 按钮点击:Response.write(<script>alert('ad')</script>); 但是执行的时候没有弹出消息框。
ISharedInterface remoteObject = (ISharedInterface)Activator.GetObject(typeof(ISharedInterface), "tcp://localhost:8080/server.rem");”
我在Client类加增加了下面的代码:
RemotingConfiguration.Configure("Client.exe.config");
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());
Console.WriteLine("Press ENTER to exit...");
Console.ReadLine();
//这样有问题吧
改成
ISharedInterface remoteObject = (ISharedInterface)Activator.GetObject(typeof(ImplementionClass), "tcp://localhost:8080/server.rem");
ISharedInterface remoteObject = (ISharedInterface)Activator.GetObject(typeof(ISharedInterface), "tcp://localhost:8080/server.rem");
Console.WriteLine("Server responds: " + remoteObject.HelloWorld("Hi Server"));其中的HelloWorld在ImplementionClass中是这样定义的:
public string HelloWorld(string input)
{
string identity = Thread.CurrentPrincipal.Identity.Name;
return "Hello to you too, " + identity;
}而且我在ISharedInterface接口和Implemention类中增加了一个返回double类型的方法:
public double Add(double a, double b)
{
return a + b;
}
在Client类中:
ISharedInterface remoteObject = (ISharedInterface)Activator.GetObject(typeof(ISharedInterface), "tcp://localhost:8080/server.rem");
Console.WriteLine("{0} add {1} is: {2}", 10.1, 9.3, remoteObject.Add(10.1, 9.3));
这样引用,也是正确的,
现在的问题是,当返回类型是string类型时是正确的,但DataSet类型就找不到反序列化方法。
为什么DataSet不能反序列化?
ISharedInterface,增加:
DataSet GetDataSet();ImplementionClass增加:
public DataSet GetDataSet()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
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);
ds.Tables.Add(dt);
return ds;
}
Client中还是用Interface来引用:
ISharedInterface remoteObject = (ISharedInterface)Activator.GetObject(typeof(ISharedInterface), "tcp://localhost:8080/server.rem");
DataSet ds = remoteObject.GetDataSet();
Console.WriteLine("Customer's Name is: {0}, birthday is: {1}", ds.Tables[0].Rows[0][0].ToString(), ds.Tables[0].Rows[0][1].ToString());这样的话运行就是正确的,
现在的问题就是,从DataSet继承的类是不是还得自己重写Serialize方法?