开发者

Why do I need the interface(decorated with [ServiceContract])?

I have a Service.svc class. In it I have:

开发者_JS百科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;
        }
    }

I have implemented the interface because I was told to do so. What im wondering is why I need to inherit an interface that is decorated with the [ServiceContract] attribute?

Would .net know? Could I still call the service if I removed this interface all together?


This attribute tells WCF that the interface defines a contract and should be exposed.
See the documentation or an arbitrary tutorial about WCF.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜