以编程方式访问TFS端点

时间:2015-12-09 18:12:03

标签: tfs automation autologin

我正在尝试使用以下代码访问TFS端点:

Uri collectionUri = new Uri("https://tfsendpoint.com:8443");
NetworkCredential networkCredential = new NetworkCredential(<username>, <password>);
WindowsCredential windowsCredential = new WindowsCredential(networkCredential);
TfsClientCredentials tfsClientCredentials = new TfsClientCredentials(windowsCredential);
tfsClientCredentials.AllowInteractive = false;
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri, tfsClientCredentials);
tpc.Authenticate();
WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();

但是tpc.Authenticate()正在抛出403 Forbidden错误。当我通过浏览器访问同一端点(https://tfsendpoint.com:8443)时,会弹出一个UI窗口来输入用户名和密码。输入后,它将登录并允许访问TFS项目。

想知道代码中需要进行哪些更改才能允许程序化登录。我尝试过BasicAuthCredential,SimpleWebTokenCredential。但获得相同的403 Forbidden结果。

1 个答案:

答案 0 :(得分:1)

将收集URL更改为以下格式:

Uri collectionUri = new Uri("http://tfsserver:8080/tfs/collectionname");