日期:2014-05-20  浏览次数:20795 次

wcf服务中没能实现接口成员,求教,谢谢!
错误提示为:“PestInfoService”不实现接口成员“IPestInfoService.GetImagoSurveys()”。“PestInfoService.GetImagoSurveys()”无法实现“IPestInfoService.GetImagoSurveys()”,因为它没有匹配的返回类型“System.Collections.Generic.List<ImagoSurvey>”。

相信代码为:
public class PestInfoService : IPestInfoService
{
  public void DoWork()
  {
  }




  #region  

  PestInfoDataContext PestDataContext = new PestInfoDataContext();
  public class ImagoSurvey
  {
  public int imagoSurveyID { get; set; }
  public decimal Longitude { get; set; }
  public decimal Latitude { get; set; }
  public int totalWaspNum { get; set; }
  }


  public List<ImagoSurvey> GetImagoSurveys()
  {
  PestInfoDataContext PestDataContext = new PestInfoDataContext();
  var imagoData = from m in PestDataContext.ImagoSurvey
  join n in PestDataContext.MonitoringPoint on m.MonitoringPointID equals n.MonitoringPointID
   
  select new ImagoSurvey
  {

  Longitude= n.Longitude,
  Latitude= n.Latitude,
  totalWaspNum= m.TotalWaspNum


  };



  return imagoData.ToList();

  }

  #endregion
}
谢谢大家能给我指点一下!

------解决方案--------------------
public class ImagoSurvey
{
public int imagoSurveyID { get; set; }
public decimal Longitude { get; set; }
public decimal Latitude { get; set; }
public int totalWaspNum { get; set; }
}

这段定义不应该放这。。

PestInfoService和IPestInfoService 内对于GetImagoSurveys方法的返回值类型要统一
------解决方案--------------------
我也觉得你定义了多个ImagoSurvey,把PestInfoService 内的ImagoSurvey删掉试一试。

下面的代码在我这里没有编译错误。

接口
C# code

namespace WcfService1
{
    public class ImagoSurvey
    {
        public int imagoSurveyID { get; set; }
        public decimal Longitude { get; set; }
        public decimal Latitude { get; set; }
        public int totalWaspNum { get; set; }
    }

    // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        void DoWork();
        [OperationContract]

        List<ImagoSurvey> GetImagoSurveys();        
    }
}