我使用TFS 2015 Webhook在发生签入时收到通知。我使用.NET 4.6创建了一个API,因此我可以收到通知。当我使用Visual Studio 2015加载API时,它完美地工作,但是一旦我将它发布到IIS 7,TFS就会开始显示状态代码:500,即使代码在没有任何异常的情况下执行。Webapi发布到IIS后TFS WebHook失败
以下是Web Api的方法。我正在写一个输出到日志,以确保它被执行。它每次都写“回归成功”。
public HttpResponseMessage Post([FromBody]Models.Content value)
{
try
{
IndexUpdater iUpdater = new IndexUpdater();
iUpdater.UpdateIndex(value.resource.changesetId);
using (StreamWriter w = File.AppendText("C:\\publish\\TFSListenerAPI\\log.txt"))
{
w.WriteLine("returning success");
}
return Request.CreateResponse(HttpStatusCode.OK);
}
catch(Exception ex)
{
using (StreamWriter w = File.AppendText("C:\\publish\\TFSListenerAPI\\log.txt"))
{
w.WriteLine("erro");
w.WriteLine(ex.Message);
}
}
}
Here is the return when I execute the API using Visual Studio, same code.
编辑:刚刚发现,只有当执行下面的方法错误500发生。奇怪的部分是代码起作用,并且内容是 成功返回。
private string GetFileContent(string tfsPath)
{
TfsTeamProjectCollection server = new TfsTeamProjectCollection(new Uri("http://tfs2015.com.br:8080/tfs/cd-jv"), new System.Net.NetworkCredential("user", "password"));
server.Authenticate();
VersionControlServer version = server.GetService(typeof(VersionControlServer)) as VersionControlServer;
Microsoft.TeamFoundation.VersionControl.Client.Item item = version.GetItem(tfsPath);
string tempFileName = System.IO.Path.GetTempFileName();
item.DownloadFile(tempFileName);
var content = File.ReadAllText(tempFileName, Encoding.GetEncoding("ISO-8859-1"));
return content;
}
GetFileContent方法和Webhook句柄部分之间的关系是什么?代码不足以让我们检查问题。 –
对不起,没有发布整个代码,我认为这将是太多的代码。但基本上,UpdateIndex方法读取它接收的chageset中的项目并将TFS路径传递给GetFileContent。 –