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”字段啊???到底怎么回事呢???
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”字段啊???到底怎么回事呢???
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”参数问题:这个参数为什么不能被序列化???
找不到“Monitoring.Period类型”,是这个原因吗???
[DataContract]
public sealed class KeyValuePair<TKey, TValue>
{
[DataMember(Name = "key")]
public TKey Key { get; set; } [DataMember(Name = "value")]
public TValue Value { get; set; }
}这个类,是定义在“接口服务类”中,还是定义在实体类“Monitor”中