c# - 为什么需要接口(interface)(用[ServiceContract]装饰)?

标签 c# asp.net wcf

我有一个 Service.svc 类。我在里面有:

public class CommentsWCFService : Objects.ISessionIDCommentWCFContract
    {
        public List<Comment> GetComments(string SessionId)
        {
            //dummy data first
            List<Comment> dummyData = new List<Comment>();

            if (SessionId == "123")
            {
                dummyData.Add(new Comment("Comment 1", DateTime.Now));
                dummyData.Add(new Comment("Comment 2", DateTime.Now));
                dummyData.Add(new Comment("Comment 3", DateTime.Now));
            }

            return dummyData;
        }
    }

我已经实现了接口(interface),因为我被告知要这样做。我想知道的是为什么我需要继承一个用 [ServiceContract] 属性装饰的接口(interface)?

.net 会知道吗?把这个接口(interface)一起去掉还能调用服务吗?

最佳答案

此属性告诉 WCF 该接口(interface)定义了一个协定并且应该公开。
查看documentation或有关 WCF 的任意教程。

关于c# - 为什么需要接口(interface)(用[ServiceContract]装饰)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6029725/

相关文章:

wcf - 您可以将 WCF 数据服务(ne OData、ne Astoria、ne ADO.NET 数据服务)与 NetTcpBinding 一起使用吗?

c# - 文件上传错误 WCF WEB API(预览版 6): Cannot write more bytes to the buffer than the configured maximum buffer size: 65536

c# - WCF 服务故障处理 WS-Discovery Resolve 消息

c# - Windows 服务似乎什么都不做 OnShutdown()

c# - 每行运行 Lua 脚本

javascript - Jquery 更改文本框边框但只更改一次

css - 无法居中数据列表

c# - 内联条件 c# - 下一个最佳解决方案?

c# - 如何在 Silverlight 中创建弹出对话框?

jquery - 下拉列表到组合框