C#错误:成员名称不能与其封闭类型和接口声明类型相同

我正在尝试为windows Azure提供appFabric服务。我是实现和EchoService,我需要通过方式和IEchoContract接口实现,所有这些都在服务器端。 所以我这样做。 在IEchoContract.cs上
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;


namespace Service
{
[ServiceContract(Name = "EchoContract", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
interface IEchoContract
{
    public interface IEchoContract
    {
        [OperationContract]
        string Echo(string text);
    }
}}
在EchoSErvice.cs上
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace Service
{
class EchoService
{
    [ServiceBehavior(Name = "EchoService", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
    public class EchoService : IEchoContract
    {
        public string Echo(string text)
        {
            Console.WriteLine("Echoing: {0}", text);
            return text;
        }
    }}}
我有两个错误,我不是C#的专家 所以第一个:当我把EchoService:IEchoContract我得到了
'EchoService': member names cannot be the same as their enclosing type
第二,当我把公共接口IEchoContract
'IEchoContract' : interfaces declare types
所以请帮忙。谢谢。     
已邀请:
您已经声明了接口和类两次 - 只声明一次。 IEchoContract.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace Service
{
    [ServiceContract(Name = "EchoContract", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
    public interface IEchoContract
    {
        [OperationContract]
        string Echo(string text);
    }
}
EchoService.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace Service
{
    [ServiceBehavior(Name = "EchoService", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
    public class EchoService : IEchoContract
    {
        public string Echo(string text)
        {
            Console.WriteLine("Echoing: {0}", text);
            return text;
        }
    }
}
    

bab

如果您在代码中看到一个名为EchoService的类中有一个名为EchoSevice的类
namespace Service
{
  class EchoService
  {
    [ServiceBehavior(Name = "EchoService", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
    public class EchoService : IEchoContract
    ...
尝试删除外部类,因为它没有意义
namespace Service
{
  [ServiceBehavior(Name = "EchoService", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
  public class EchoService : IEchoContract
  ...
您还必须删除外部接口,因为它们也被定义了两次(可能是您的类最终定义两次的原因)     
您在EchoService类中定义了一个EchoService类 - 这是不可能的。只需删除外部“类EchoService”,你应该没问题。     
在EchoService.cs中,您不能调用内部类EchoService,因为您已经在其上面有一个类EchoService。您需要重命名其中一个。     

要回复问题请先登录注册