修饰符'public'对此项无效

G G*_* Gr 2 c# asp.net web-services

namespace WcfService1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface HelloWorldService
    {
        [OperationContract]
        [WebGet(UriTemplate = "")]

        public string HelloWorld() //here
        {
            return "Hello world!";
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Error   1   The modifier 'public' is not valid for this item
Run Code Online (Sandbox Code Playgroud)

这是我在svc.cs文件中的内容

public class Service1 : HelloWorldService
{
    public string HelloWorld()
    {
        return string.Format("Hello World!");
    }
}
Run Code Online (Sandbox Code Playgroud)

这实际上来自我的uni教程:

与上周我们首先为我们的服务创建接口的情况不同,我们只是在第一个示例中创建WCF服务对象.这是为了在教程中节省时间.最佳实践意味着我们应该为所有服务创建接口,这些接口与定义的服务合同相关.首先在Visual Studio 2008中创建一个新项目(记得添加System.ServiceModel和System.ServiceModel.Web引用,以及这两个名称空间的using声明),并添加以下类定义:

[ServiceContract]
public class HelloWorldService
{
[OperationContract]
[WebGet(UriTemplate="")]
public string HelloWorld()
{
return "Hello world!";
}
}
Run Code Online (Sandbox Code Playgroud)

您应该熟悉上周教程中此WCF服务的基本结构.不同之处在于我们添加到方法的额外属性:[WebGet(UriTemplate ="")]此属性表明服务接收HTTP GET消息(WebGet部分),并且URL的其余部分与服务终点(在后面的例子后,这将变得更加清晰).要托管此服务,我们需要以下主要应用程序:

Jar*_*Par 6

interface声明中的成员不能拥有访问修饰符.它们隐含地具有与包含相同的可访问性interface.如果您可以访问界面,则可以访问其所有成员