WCF,“反序列化”出错

starrymonitor 2012-05-29 07:38:07
WCF,“反序列化”出错,Why???


public System.Collections.ObjectModel.ObservableCollection<MyCharts.MyChartsService.Monitoring> EndGetMonitoringEntityData(System.IAsyncResult result) {
object[] _args = new object[0];
System.Collections.ObjectModel.ObservableCollection<MyCharts.MyChartsService.Monitoring> _result = ((System.Collections.ObjectModel.ObservableCollection<MyCharts.MyChartsService.Monitoring>)(base.EndInvoke("GetMonitoringEntityData", _args, result)));
return _result;

错误信息如下:

格式化程序尝试对消息反序列化时引发异常: 尝试对参数 进行反序列化时出错: monitordate。InnerException 消息是““EndElement”命名空间“”中的“monitordate”并非所需元素。所需元素应为“key”。”。有关详细信息,请参见 InnerException。



“启动Silverlight 的WCF服务 ” 序列化的类:

1、父类(其中有一个抽象方法)

public abstract class Monitoring
{
#region 检索条件

public EnergyType Type
{
get; set;
}

public KeyValuePair<Period, string> Date
{
get; set;
}
public KeyValuePair<MonitorType, string> Target
{
get; set;
}
public string UseType
{
get; set;
}
#endregion

#region 检索结果
public string SN
{
get;
set;
}
public string U
{
get; set;
}
public double V
{
get; set;
}
public double ECV
{
get;
set;
}

public double CUV
{
get;
set;
}
public string SS
{
get
{
switch (Target.Key)
{
case MonitorType.D:
return DN;
case MonitorType.C:
return CN;
case MonitorType.B:
return BN;
case MonitorType.F:
return FN;
case MonitorType.FR:
return string.Format("{0}({1})", FN, RN);
case MonitorType.R:
return RN;
case MonitorType.E:
return EN;
}
return string.Empty;
}
}
public string E
{
get;
set;
}
public string EN
{
get;
set;
}
public string R
{
get;
set;
}
public string RN
{
get;
set;
}
public string F
{
get;
set;
}
public string FN
{
get;
set;
}
public string B
{
get;
set;
}
public string BN
{
get;
set;
}
public string C
{
get;
set;
}
public string CN
{
get;
set;
}
public string D
{
get;
set;
}
public string DN
{
get;
set;
}
public abstract double[] Datas
{
get;
}
#endregion

#region ENUM
public enum EnergyType
{

EM,

WM,

GM,

OTHER,

ALL
}

public enum Period
{

D,

M,

Y,

X
}


public enum MonitorType
{

E = 0,

R = 1,

FR = 2,

B = 3,

C = 4,

D = 5,

F= 6
}
#endregion
}

2、子类(实现了父类的“Datas”方法):

public class MonitoringYear : Monitoring
{
public override double[] Datas
{
get
{
return new [] { M01, M02, M03, M04, M05, M06, M07, M08, M09, M10, M11, M12 };
}
}


public double M01
{
get; set;
}


public double M02
{
get;
set;
}


public double M03
{
get;
set;
}


public double M04
{
get;
set;
}


public double M05
{
get;
set;
}


public double M06
{
get;
set;
}


public double M07
{
get;
set;
}


public double M08
{
get;
set;
}


public double M09
{
get;
set;
}


public double M10
{
get;
set;
}


public double M11
{
get;
set;
}

public double M12
{
get;
set;
}
}

问题:为什么会反序列化出错呢??? 是因为抽象方法“Datas”吗??? 在这两个“类”中也没有“monitordate”字段啊???到底怎么回事呢???
...全文
218 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
starrycheng 2012-06-01
  • 打赏
  • 举报
回复
KeyValuePair”支持默认的序列化啊,实体类“Monitor”没有定义契约也没事。

public List<MonitoringEntity> GetMonitoringReggionDatas(Monitoring.EnergyType energytype, KeyValuePair<Monitoring.Period, string> monitordate, KeyValuePair<Monitoring.MonitorType, string> monitortype, string meterusetype, bool issubstation)

就是调用“服务接口类”的“服务方法”中“不能有”KeyValuePair“类型???Why???

您好,谢谢您。


[DataContract]
public sealed class KeyValuePair<TKey, TValue>
{
[DataMember(Name = "key")]
public TKey Key { get; set; }

[DataMember(Name = "value")]
public TValue Value { get; set; }
}

这个类,是定义在“接口服务类”中,还是定义在实体类“Monitor”中。。。
starrycheng 2012-05-29
  • 打赏
  • 举报
回复
[OperationContract]
public List<Monitoring> GetMonitoringEntityData(Monitoring.EnergyType energytype, KeyValuePair<Monitoring.Period, string> monitordate, KeyValuePair<Monitoring.MonitorType, string> monitortype, string meterusetype, bool issubstation)
{
List<Monitoring> MonitoringEntityDatas = new Mycems.BLL.MonitoringManager(issubstation).GetMonitorDatas(energytype, monitordate, monitortype, meterusetype);
return MonitoringEntityDatas;
}
有一个“KeyValuePair<Monitoring.Period, string> monitordate”参数

问题:这个参数为什么不能被序列化???
starrycheng 2012-05-29
  • 打赏
  • 举报
回复
不知所以然啊。。。学习了。。。

8,757

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧