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