public HttpResponseMessage GetComments(string blogId, string postId, HttpRequestMessage request, int pageIndex = 1, int pageSize = 10) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); try { ICommentsService commentsService = ObjectFactory.GetInstance <ICommentsService>(); var comments = commentsService.GetAllFromPost(String.Format("posts/{0}", postId), pageIndex, pageSize); if (comments != null) { if (this.ClientAcceptsMediaType("text/html", request)) { var commentsHtml = comments.GenerateCommentsHtml(); response.Content = new ObjectContent <string>(commentsHtml, "text/html"); } else { SyndicationFeed postCommentsFeed = new SyndicationFeed { Title = new TextSyndicationContent( String.Format("Post {0} comments", postId)), LastUpdatedTime = new DateTimeOffset(DateTime.Now) }; postCommentsFeed.Links.Add(SyndicationLink.CreateSelfLink(request.RequestUri)); List <SyndicationItem> itemList = new List <SyndicationItem>(); postCommentsFeed.Items = itemList; foreach (var comment in comments) { SyndicationItem item = new SyndicationItem { Id = comment.Id, LastUpdatedTime = comment.updated, PublishDate = comment.published }; item.Links.Add(SyndicationLink.CreateSelfLink(new Uri(String.Format("{0}/blogs/{1}/posts/{2}/{3}", this.serviceURI, blogId, postId, comment.Id)))); item.Links.Add(SyndicationLink.CreateAlternateLink(request.RequestUri, "text/html")); item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/blogs/{1}/posts/{2}", this.serviceURI, blogId, postId)), "service.post", "Parent post", "application/atom+xml;type=feed", 0)); item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/blogs/{1}/posts/{2}/{3}", this.serviceURI, blogId, postId, comment.Id)), "service.edit", "Edit comment", "application/atom+xml;type=feed", 0)); var pagingLinks = this.BuildPagingLinks(commentsService.Count(), pageIndex, pageSize, request.RequestUri); foreach (var link in pagingLinks) { item.Links.Add(link); } item.Authors.Add(new SyndicationPerson(string.Empty, comment.author, string.Empty)); item.Content = SyndicationContent.CreatePlaintextContent(comment.content); itemList.Add(item); } SyndicationFeedFormatter formatter = null; if (this.ClientAcceptsMediaType("application/atom+xml", request)) { formatter = postCommentsFeed.GetAtom10Formatter(); } else { if (this.ClientAcceptsMediaType("application/rss+xml", request)) { formatter = postCommentsFeed.GetRss20Formatter(); } } response.Content = new ObjectContent(typeof(SyndicationFeedFormatter), formatter); } } else { response.StatusCode = HttpStatusCode.NoContent; } } catch (Exception) { response.StatusCode = HttpStatusCode.InternalServerError; } return(response); }