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.
精彩评论