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
,所以请帮忙。谢谢。
I am trying to lauch a service for appFabric for windows Azure. I am implement and EchoService and i need to implement by the way and IEchoContract interface, all of this on server side.
So I proceed like this.
On the 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);
}
}}
And on 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;
}
}}}
I got two errors, i am not an expert on C#
So first one: When i put EchoService : IEchoContract i got
'EchoService': member names cannot be the same as their enclosing type
Second when i put public interface IEchoContract
'IEchoContract' : interfaces declare types
So please help. Thx.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您已声明接口和类两次 - 每个仅声明一次。
IEchoContract.cs:
EchoService.cs:
You have declared the interface and the class twice - declare each just once.
IEchoContract.cs:
EchoService.cs:
如果您在代码中看到在名为 EchoService 的类中有一个名为 EchoSevice 的类,
请尝试删除外部类,因为它在这里没有意义
您还必须删除外部接口,因为这些接口也定义了两次(可能是您的原因)类最终也定义了两次)
If you see in your code you have a class called EchoSevice inside a class called EchoService
Try removing the outer class as it has no meaning here
You will have to remove your outer interface also, since those are also defined twice (probably the reason why your classes ended up defined twice as well)
您在 EchoService 类中定义 EchoService 类 - 这是不可能的。只需删除外部的“EchoService 类”就可以了。
You define an EchoService class in the EchoService class - that is not possible. Just remove the outer "class EchoService" and you should be fine.
在 EchoService.cs 中,您无法调用内部类 EchoService,因为它上面已经有一个类 EchoService。您需要重命名其中之一。
In EchoService.cs, you can't call the internal class EchoService as you already have a class EchoService above it. You need to rename one of them.