为什么我需要接口(用[服务合同]装饰)

本文关键字:合同 服务 装饰 接口 为什么 | 更新日期: 2023-09-27 17:56:33

我有一个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;
        }
    }

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

.net 会知道吗?如果我一起删除此接口,我还能调用该服务吗?

为什么我需要接口(用[服务合同]装饰)

此属性告知 WCF 接口定义协定,应公开。
请参阅有关 WCF 的文档或任意教程。