我想你的WCF REST入門套件。嘗試將WCF REST入門工具包看作只是一個配置爲在http環境中輕鬆設置的WCF服務。爲WCF REST入門工具包設置的默認模板旨在用作示例。您將不得不創建自己的簽名或使其符合您的需求。
您需要關注的關鍵部分是.svc文件中的代碼(無法雙擊它,您必須選擇打開方式)和[ServiceContract]接口。
在提供的代碼中修改[ServiceContract]接口,看起來就像是對於常規的WCF服務。
這是您的需要修改
[ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceContract]
public partial class LibraryFeed
{
public LibraryFeed()
{
}
/// <summary>
/// Returns an Atom feed.
/// </summary>
/// <returns>Atom feed in response to a HTTP GET request at URLs conforming to the URI template of the WebGetAttribute.</returns>
[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();
}
/// <summary>
/// Returns an Atom feed.
/// </summary>
/// <returns>Atom feed in response to a HTTP GET request at URLs conforming to the URI template of the WebGetAttribute.</returns>
[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();
}
/// <summary>
/// Returns an Atom feed.
/// </summary>
/// <returns>Atom feed in response to a HTTP GET request at URLs conforming to the URI template of the WebGetAttribute.</returns>
[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());
}
}
的Atom發佈頻道我想通了這一點,最終的樣本。我試圖將模板項目作爲我的開發基礎,而不僅僅是樣本,它們是。我剛剛創建了自己的WCF服務,並重新使用Starter Kit中的擴展庫。 – 2009-02-16 14:17:54