c# - 修饰符 'public' 对此项目无效

标签 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!";
        }
    }
}

我收到这个错误:

Error   1   The modifier 'public' is not valid for this item

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

public class Service1 : HelloWorldService
{
    public string HelloWorld()
    {
        return string.Format("Hello World!");
    }
}

这实际上来 self 大学的教程:

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

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

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

最佳答案

interface 声明中的成员不能有访问修饰符。它们隐含地具有与包含 interface 相同的可访问性。如果你可以访问一个接口(interface),你就可以访问它的所有成员

关于c# - 修饰符 'public' 对此项目无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9729225/

相关文章:

c# - 如何从 DLL 获取 MySqlConnection 对象

c# - 更改 GridView 中列的标题文本

java - 使用 spring 框架在没有 wsdl 的情况下使用 SOAP Web 服务

web-services - JAX-WS 更改 WebParam 的命名空间

c# - 在 VS Package 项目中获取 dte2 或 TeamFoundationServerExt 对象?

c# - nservicebus - 多个端点错误

c# - 正则表达式匹配不包括下划线的字符串

asp.net - IIS/SQL Server : Not enough storage is available to process this command 错误

asp.net - 如何将 ASP.NET FormView 绑定(bind)到单个记录?

web-services - 如何模拟 WS 客户端并在 Camel route 提供响应