所以这里我将从Visual Studio Team Services获取评论,通过从VSO传递工作项的ID我应该能够从任何给定的工作项中提取评论历史记录,因为我将'id'传递给GetCommentsAsync我得到注释的null结果,即使我给api的workItem id确实有注释。
public WorkItemComments GetPageOfWorkItemComments(string VSTSID)
{
int id = Int32.Parse(VSTSID);
VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken);
VssConnection connection = new VssConnection(new Uri(_uri), credentials);
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
WorkItemComments result = workItemTrackingClient.GetCommentsAsync(id).Result;
Console.WriteLine("Total Revision Count: {0}", result.TotalCount);
Console.WriteLine("From Revision Count: {0}", result.FromRevisionCount);
Console.WriteLine("Comments...");
foreach (var comments in result.Comments)
{
Console.WriteLine("{0}", comments.Text);
Console.WriteLine();
}
return result;
}
当我的代码开始查看注释结果并抛出错误时,它打破了foreach:Object reference not set to an instance of an object.
从这里开始我的电话:
public string CreateWorkItem(string title, string description, string
PTID, string assigned, string VSTSID)
{
Response response;
VssObject work = new VssObject();
try
{
//work.CreateWIUsingClientLib(title, description, PTID,
assigned, VSTSID);
//work.GetWorkItemById(PTID);
work.GetPageOfWorkItemComments(VSTSID);
response = new Response(work);
return response.BuildJsonResponse();
}
catch (Exception ex)
{
_logger.Error(ex, "{Application:l} - {SourceContext:l}: Error
calling 'VssAPI'.", applicationName);
return ex.Message;
}
}
使用GET通过邮递员进行测试:
http://localhost:57765/API.svc/CreateWorkItem?title=blash&description=bkkdkd&ptid=BDC19072-9016-4CB8-8741-CDFAF52D0E40&assigned=assigned&vstsid=543
最后稳定版本的REST Web Api库包含一些已知的注释问题:.NET Client Library - WorkItemTrackingHttpClient GetCommentsAsync does not return the list of comments