2
我有一個Service.svc類。我有:爲什麼我需要界面(用[ServiceContract]裝飾)?
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共享接口」,這裏有一些[鏈接](http://blogs.crankygoblin.com/blogs/geoff.appleby/archive/2006/06/08/Sharing-Interfaces-in-WCF.aspx)[另一個一個](http://weblogs.asp.net/avnerk/archive/2006/05/17/Share-your-interfaces-_2D00_-avoid-static-proxies_2E00_.aspx) – BenCr 2011-05-17 10:52:04