如何将该“类”,用WCF发布出去,被SL使用???该类是来自“asp.net三层”的中的“BLL”层的,内容如下:
using System.Collections.Generic;
using System.Linq;
using Mycems.DAL;
using Mycems.Model;namespace Mycems.BLL
{
  public class MonitoringManager
  {
  #region 构造函数
  private readonly MonitoringService service;
  public MonitoringManager() : this(false)
  {
  }
    
  public MonitoringManager(bool issubstation)
  {
  service = new MonitoringService(issubstation);
  service.IsIncludeWater = false;
  }  public MonitoringManager(bool issubstation, bool isincludewater)
  {
  service = new MonitoringService(issubstation);
  service.IsIncludeWater = isincludewater;
  }
  #endregion  public List<Monitoring> GetMonitorDatas(Monitoring.EnergyType energytype, KeyValuePair<Monitoring.Period, string> monitordate, KeyValuePair<Monitoring.MonitorType, string> monitortype, string meterusetype)
  {
  return GetMonitorDatas(energytype, energytype.ToString(), monitordate, monitortype, meterusetype);
  }  public List<Monitoring> GetMonitorDatas(Monitoring.EnergyType energytype, string energytypecode, KeyValuePair<Monitoring.Period, string> monitordate, KeyValuePair<Monitoring.MonitorType, string> monitortype, string meterusetype)
  {
  var result = new List<Monitoring>();  var total = string.IsNullOrEmpty(meterusetype) || meterusetype.StartsWith(",") || meterusetype.StartsWith("*");  service.IsAutoStatistics = energytype != Monitoring.EnergyType.OTHER;  service.IsManualStatistics = total && (monitordate.Key == Monitoring.Period.Y || monitordate.Key == Monitoring.Period.X) && monitortype.Key != Monitoring.MonitorType.D;  if (total)
  {
  result = service.GetMonitorDetailDatas(energytype, energytypecode, monitordate, monitortype, string.Empty);  if (!string.IsNullOrEmpty(meterusetype)) meterusetype = meterusetype.Substring(1);
  if (!string.IsNullOrEmpty(meterusetype) && meterusetype.StartsWith(",")) meterusetype = meterusetype.Substring(1);
  }  if (!string.IsNullOrEmpty(meterusetype) && !meterusetype.StartsWith(","))
  {
  if (service.IsAutoStatistics && !service.IsSubstation) result.AddRange(service.GetMonitorDetailDatas(energytype, energytypecode, monitordate, monitortype, meterusetype));
  }  #region 多日期时的处理
  var dates = monitordate.Value.Split(',');
  if (dates.Length > 1 && (monitortype.Value != "*"))
  {
  var newresult = new List<Monitoring>();
  foreach (var date in dates)
  {
  var itemofdate = result.Where(item => item.SN == date).FirstOrDefault();
  if (itemofdate == null)
  {
  switch (monitordate.Key)
  {
  case Monitoring.Period.Y:
  itemofdate = new MonitoringYear();
  break;
  case Monitoring.Period.M:
  itemofdate = new MonitoringMonth();
  break;
  default:
  itemofdate = new MonitoringDay();
  break;
  }  itemofdate.SN = date;
  itemofdate.U = result[0].U;
  itemofdate.V = result[0].V;
  itemofdate.E = result[0].E;
  itemofdate.EN = result[0].EN;
  itemofdate.R = result[0].R;
  itemofdate.RN = result[0].RN;
  itemofdate.F = result[0].F;
  itemofdate.FN = result[0].FN;
  itemofdate.B = result[0].B;
  itemofdate.BN = result[0].BN;
  itemofdate.C = result[0].C;
  itemofdate.CN = result[0].CN;
  itemofdate.D = result[0].D;
  itemofdate.DN = result[0].DN;
  itemofdate.Type = result[0].Type;
  itemofdate.Date = result[0].Date;
  itemofdate.Target = result[0].Target;
  itemofdate.UseType = result[0].UseType;  result.Add(itemofdate);
  }  newresult.Add(itemofdate);
  }
  return newresult;
  }
  #endregion
  return result;
  }
  public Dictionary<string,double[]> GetAreaHeadCount()
  {
  return service.GetAreaHeadCount();
  }
  #endregion
  }  #region 扩展方法
  public static class ListMonitorExtention
  {
  public static List<Monitoring> Sum(this List<Monitoring> source, List<Monitoring> another)
  {
  foreach (var S in source)
  {
  var item = (MonitoringYear)S;
  foreach (var A in another)
  {
  if (S.SN == A.SN && S.E == A.E && S.R == A.R && S.F == A.F && S.B == A.B && S.C == A.C && S.D == A.D)
  {
  item.M01 += A.Datas[0];
  item.M02 += A.Datas[1];
  item.M03 += A.Datas[2];
  item.M04 += A.Datas[3];
  item.M05 += A.Datas[4];
  item.M06 += A.Datas[5];
  item.M07 += A.Datas[6];
  item.M08 += A.Datas[7];
  item.M09 += A.Datas[8];
  item.M10 += A.Datas[9];
  item.M11 += A.Datas[10];
  item.M12 += A.Datas[11];  if (string.IsNullOrEmpty(item.SN)) item.SN = A.SN;  another.Remove(A);
  break;
  }
  }
  }
  source.AddRange(another);  return source;
  }
  }
  #endregion
}问题:如何将该“类”,和该类中的“所有方法”用“WCF”发布出去,可以在客户端被“SL”使用,进行查询???

解决方案 »

  1.   

    用接口把方法抽象出来,
    用实体类把参数和用到的自定义类型提取出来。
    接口的public interface xxxxx{}上面加上Attribute : ServiceContract
    接口内声明的方法上方加上Attribute :               OperationContract
    实体类上方加上Attribute :                         DataContract
    实体类属性上方加上Attribute:                      DataMember另,该类需要使用ServiceHost或者IIS寄宿服务,然后SL工程上 Add Service Reference
      

  2.   


    使用的是“启用了 Silverlight的 WCF 服务”,内容如下:
    using System;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Activation;[ServiceContract(Namespace = "")]
    [SilverlightFaultBehavior]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ChartsService
    {
    [OperationContract]
    public void DoWork()
    {
    // 在此处添加操作实现
    return;
    }// 在此处添加更多操作并使用 [OperationContract] 标记它们
    }是不是把“BLL 层”下的“MonitoringManager”类引用过来,添加上这些方法就可以了呢?
      

  3.   


    像使用Webservice一样添加服务引用。然后使用命名空间
      

  4.   


    嗯,把类改成了这个样子,使用了“RIA WCF Service”,但是好像不能标记构造函数。

    [ServiceContract(Namespace = "")]
    [SilverlightFaultBehavior]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ChartsService
    {
    [OperationContract]
    public void DoWork()
    {
    return;
    } // 在此处添加更多操作并使用 [OperationContract] 标记它们    #region 构造函数
            private readonly MonitoringService service;        [OperationContract]
            public ChartsService() : this(false)
            {
            }
            
            [OperationContract]
            public ChartsService(bool issubstation)
            {
                service = new MonitoringService(issubstation);
                service.IsIncludeWater = false;
            }        [OperationContract]
            public ChartsService(bool issubstation, bool isincludewater)
            {
                service = new MonitoringService(issubstation);
                service.IsIncludeWater = isincludewater;
            }
            
            问题:“[OperationContract]”标记好像对构造函数无效,那么“构造函数”应该怎样对外发布呢?
    错误信息如下:
    错误 1 特性“OperationContract”对此声明类型无效。它只对“method”声明有效。 C:\Users\Administrator\Desktop\GLLG(Preview2.0)\Mycems.UI\App_Code\ChartsService.cs 30 10 C:\...\Mycems.UI\
            #endregion      
            [OperationContract]
            public List<Monitoring> GetMonitorDatas(Monitoring.EnergyType energytype, KeyValuePair<Monitoring.Period, string> monitordate, KeyValuePair<Monitoring.MonitorType, string> monitortype, string meterusetype)
            {
                return GetMonitorDatas(energytype, energytype.ToString(), monitordate, monitortype, meterusetype);
            }
      

  5.   

    "WCF 服务"没有办法公布“服务类的构造函数”吗?