我认为你对WCF REST初学者工具包的过度思考。试着将WCF REST Starter工具包看作是一个WCF服务,它的配置便于在http环境中进行设置。为WCF REST初学者工具包设置的默认模板将用作示例。你只需创建自己的签名或修改他们的签名以满足你的需要。
您需要重点关注的关键部分是.svc文件中的代码(双击无法访问它,您必须选择打开方式)和[ServiceContract]接口。
在提供的代码隐藏中修改[ServiceContract]接口,使其看起来与常规WCF服务一样。
下面是一个根据您的需要修改的ATOM发布提要示例
[ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceContract]
public partial class LibraryFeed
{
public LibraryFeed()
{
}
[WebHelp(Comment = "Gets a list of Books.")]
[WebGet(UriTemplate = "/books/?numItems={numItems}")]
[OperationContract]
public Atom10FeedFormatter GetBooks(int numItems)
{
var books = GetBooks();
List<SyndicationItem> items = GetItems(books, numItems);
SyndicationFeed feed = CreateFeed(items);
WebOperationContext.Current.OutgoingResponse.ContentType = ContentTypes.Atom;
return feed.GetAtom10Formatter();
}
[WebHelp(Comment = "Gets a single author.")]
[WebGet(UriTemplate = "/authors/?numItems={numItems}")]
[OperationContract]
public Atom10FeedFormatter GetAuthors(int numItems)
{
var authors = GetAuthors();
List<SyndicationItem> items = GetItems(authors, numItems);
SyndicationFeed feed = CreateFeed(items);
WebOperationContext.Current.OutgoingResponse.ContentType = ContentTypes.Atom;
return feed.GetAtom10Formatter();
}
[WebHelp(Comment = "Gets a list of Authors.")]
[WebGet(UriTemplate = "/authors/{id}")]
[OperationContract]
public Atom10FeedFormatter GetAuthor(string id)
{
var author = GetSingleAuthor(id);
WebOperationContext.Current.OutgoingResponse.ContentType = ContentTypes.Atom;
return GetItem(author.GetAtom10Formatter());
}
}