Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未在服务中实现接口成员_C#_Asp.net Mvc 3_Wcf - Fatal编程技术网

C# 未在服务中实现接口成员

C# 未在服务中实现接口成员,c#,asp.net-mvc-3,wcf,C#,Asp.net Mvc 3,Wcf,首先,如果对这个问题的提及不正确,我道歉 我正在开发一个三层的mvc3应用程序。在业务层中,我需要创建一个调用数据访问层的服务,以便检索现有城镇的列表 我的ITown界面如下: [ServiceContract] public interface ITown { [OperationContract] IEnumerable<Town> GetAllTowns(); } 问题出在上面的代码中。我在类声明公共类Town:ITown中的Town下遇到错误 'Busine

首先,如果对这个问题的提及不正确,我道歉

我正在开发一个三层的
mvc3
应用程序。在业务层中,我需要创建一个调用数据访问层的服务,以便检索现有城镇的列表

我的
ITown
界面如下:

[ServiceContract]
public interface ITown
{
    [OperationContract]
    IEnumerable<Town> GetAllTowns();
}
问题出在上面的代码中。我在类声明
公共类Town:ITown
中的
Town
下遇到错误

'Business.Town' does not implement interface member 'Business.ITown.GetAllTowns()'. 
'Business.Town.GetAllTowns()' cannot implement 'Business.ITown.GetAllTowns()'
because it does not have the matching return type of 'System.Collections.Generic.IEnumerable<Business.Town>'.
因此,基本上我所做的是从
Town.svc.cs
类调用
DATown
GetAllTowns()
方法

我到处寻找其他类似的问题;主要是说其中一个方法中有一个正确的参数。我认为我的代码并非如此

如果有人能帮我找出问题所在,我将不胜感激


提前感谢。

在您的Town类中,您有一个
IEnumerable
,在界面中,您只得到了
IEnumerable
,但在您的错误中,它显示该界面使用的是
Business.Town
,而不是
Common.Town
。问题是它们之间并不相同


如果您更改界面,使IEnumerable也是Common.Town,那么您应该可以。

从我看到的情况来看,您的返回类型不正确-您在ITown的Town是business.Town,而在service类中返回Common.Town。尝试回归商业。svc的城镇

'Business.Town' does not implement interface member 'Business.ITown.GetAllTowns()'. 
'Business.Town.GetAllTowns()' cannot implement 'Business.ITown.GetAllTowns()'
because it does not have the matching return type of 'System.Collections.Generic.IEnumerable<Business.Town>'.
public class DATown : Connection
{
    //Constructor
    public DATown()
        :base()
    { }

    public IEnumerable<Town> GetAllTowns()
    {
        return entities.Town.AsEnumerable();
    }
}