2012-09-07 39 views
3

我們試圖驗證到我們的使用TeamFoundationServer .NET控件中承載在C#TFS service account,這裏是我的代碼:無法從C#代碼連接到我的TFS服務器

NetworkCredential tfsCredential = new NetworkCredential(username, password); 
TeamFoundationServer tfsServer = new TeamFoundationServer(tfsAddress, tfsCredential); 

tfsServer.Authenticate(); 

注意,這是一個本地TFS服務器,它是託管的TFS服務tfspreview.com,我們嘗試使用Windows Live帳戶和備用身份驗證憑據進行登錄,但每次我們嘗試進行身份驗證時,Internet Explorer將在新窗口中打開並要求提供憑據。

如果我們使用IE提示連接它的工作原理,但我們要保存憑證並連接到服務器,而無需每次都詢問憑據,

回答

0

您可以根據服務器

的模擬驗證碼嘗試
var serverUrl = ""; 

ICredentials credentials = new NetworkCredential(username, password, domain); 
ICredentialsProvider TFSProxyCredentials = new NetworkCredentialsProvider(credentials); 

TfsTeamProjectCollection currentCollection = new TfsTeamProjectCollection(new Uri(serverUrl), credentials); 


// Get the TFS Identity Management Service 
IIdentityManagementService identityManagementService = currentCollection.GetService<IIdentityManagementService>(); 
// Look up the user that we want to impersonate 
TeamFoundationIdentity identity = identityManagementService.ReadIdentity(IdentitySearchFactor.AccountName, username, MembershipQuery.None, ReadIdentityOptions.None); 


// Open collection impersonated 
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(serverUrl), credentials, TFSProxyCredentials, identity.Descriptor); 

//For example we can access to service WorkItemStore 
var workItemStore = tfs.GetService<WorkItemStore>(); 
+0

它仍然提示一個IE窗口,要求我的憑據。第一個操作是'currentCollection.GetService ();'。這是正常的還是我的憑據,在我的代碼中無法正常工作,它不應該做任何提示。 – user1655125

+0

我認爲你的憑證有問題 –

+0

這當然是合乎邏輯的扣除,但如果我在提示中輸入它們,相同的憑證也可以正常工作 – user1655125

0

Tfspreview.com現在支持基本身份驗證,它可以消除所有顯示的IE。請參閱here瞭解如何爲您的tfspreview.com進行設置,然後使用您配置的用戶名和密碼。

1

您可以在配置文件下配置基本身份驗證,也可以使用服務憑據。這一切都取決於你需要什麼樣的權限。基本身份驗證在用戶帳戶下運行,在服務帳戶擁有較高權限的情況下,這往往是不好的做法。

配置了TF服務

對於基本的用戶身份驗證基本身份驗證,你應該連接到TF服務,並指示打開您的個人資料。您的個人資料上有一個「憑證」標籤,可讓您配置這些憑證。這對通過API進行每用戶/用戶訪問是很好的,但如果你想通過服務器或服務來運行,這並不好。

Configure basic authentication for TF Service

檢索TFS服務憑證

我創建了一個應用程序調用的TFS Service Credential Viewer,使您可以檢索你的TF服務實例的服務憑據。這與測試服務器在將本地配置爲在雲環境中工作時所執行的Build &一樣。

Retrieve TFS Service Credentials

我希望這有助於...