日期:2014-05-18  浏览次数:20854 次

客户端和服务器端,实体对象使用
项目有asp.net服务器端,Silverlight客户端,中间使用“启用 Silverlight的WCF服务”进行通信,共用实体对象“Monitoring”。

asp.net服务器端:

[OperationContract]
  public List<Monitoring> GetMonitorDatasService(Monitoring.EnergyType energytype, KeyValuePair<Monitoring.Period, string> monitordate, KeyValuePair<Monitoring.MonitorType, string> monitortype, string meterusetype)
  {
  return GetMonitorDatas(energytype, energytype.ToString(), monitordate, monitortype, meterusetype);
  }

Silverlight客户端:
 private void ChartsDataBind()
  {
   
  //参数①能源类型

  //参数②监测日期
  KeyValuePair<MyCharts.ChartsServiceClient.Monitoring.Period, string> monitordate = new KeyValuePair<Monitoring.Period, string>(Monitoring.Period.Y, "2011");

  //参数③监测对象
  KeyValuePair<Monitoring.MonitorType, string> monitortype = new KeyValuePair<Monitoring.MonitorType, string>(Monitoring.MonitorType.B, "310000Fa001");

  //参数④分项能耗
  var meterusetype = "";

  //参数⑤按变电所统计
  var issubstation = false;
   
  ChartsServiceClient.ChartsServiceClient serviceclient = new ChartsServiceClient.ChartsServiceClient();
  serviceclient.ChartsServiceInitializeOneAsync(issubstation);
  serviceclient.GetMonitorDatasServiceCompleted += new EventHandler<GetMonitorDatasServiceCompletedEventArgs>(serviceclient_GetMonitorDatasServiceCompleted);
  serviceclient.GetMonitorDatasServiceAsync(Monitoring.EnergyType.EM, monitordate, monitortype, meterusetype);
   
  }

说明:“Monitoring对象”,在“Model类库”中,服务器端(asp.net站点)添加了关于“Model类库”的引用。而客户端(Silverlight),没有添加“Monitoring对象”,但是添加了“WCF服务引用(using MyCharts.ChartsServiceClient;)”,这样“Monitoring对象”也被加载了进来。

问题一:“客户端(Silverlight)”需不需要引入“Monitoring对象”?

问题二:在“客户端(Silverlight)”新建一个一样的“Monitoring对象”,但是使用时提示,需要进行转化。要从“Silverlight项目”下的“Monitoring对象”转化为“MyCharts.ChartsServiceClient”下的“Monitoring对象”?而他们的内容是一样的。Why???


------解决方案--------------------
显然不是一个命名空间下的东西,也许是内容一样
------解决方案--------------------
用JSON序列化可以无视namespace
------解决方案--------------------
silverlight是通过web service访问服务器的,MyCharts.ChartsServiceClient”下的“Monitoring对象”是客户端的代理类(根据wsdl)生成的对象,跟服务器端的Monitoring当然不是一个东西,但是结构基本相同(List好像缺省是序列化成数组)。你如果知道web service的原理,就很容易理解了。