我使用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。 –