I have the following code on my windows form application:
// Connect to server
var tfs = new TeamFoundationServer(tfsServer, credentials);
try
{
tfs.EnsureAuthenticated();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
};
This is working. The problem is TeamFoundationServer
is an obsolete class.
The TeamFoundationServer class is obsolete. Use the TfsTeamProjectCollection or TfsConfigurationServer classes to talk to a 2010 Team Foundation Server. In order to talk to a 2005 or 2008 Team Foundation Server use the TfsTeamProjectCollection class.
I am using the below code now but it doesn't validate my credentials. What did I do wrong here?
NetworkCredential credentials = new NetworkCredential(username, password, domain);
MyCredentials credentials = new MyCredentials(username, password, domain);
TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsServer), credentials);
try
{
tfs.EnsureAuthenticated();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
This is the MyCrendentials class:
private class MyCredentials : ICredentialsProvider
{
private NetworkCredential credentials;
#region ICredentialsProvider Members
public MyCredentials(string user, string domain, string password)
{
credentials = new NetworkCredential(user, password, domain);
}
public ICredentials GetCredentials(Uri uri, ICredentials failedCredentials)
{
return credentials;
}
public void NotifyCredentialsAuthenticated(Uri uri)
{
throw new NotImplementedException();
}
#endregion
}
Thanks in advance!
I struggled with the same thing this morning. You don't need any of that interface/implementation code anymore. This is how I got it to work:
// Translate username and password to TFS Credentials
ICredentials networkCredential = new NetworkCredential(tfsUsername, tfsPassword, domain);
WindowsCredential windowsCredential = new WindowsCredential(networkCredential);
TfsClientCredentials tfsCredential = new TfsClientCredentials(windowsCredential, false);
// Connect to TFS Work Item Store
Uri tfsUri = new Uri(@"http://my-server:8080/tfs/DefaultCollection");
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(tfsUri, tfsCredential);
WorkItemStore witStore = new WorkItemStore(tfs);
I know it's an old question, but I was asking the same question at one point.
NetworkCredential credentials = NetworkCredential("User", "Password", "Domain");
TfsConfigurationServer tfs = new TfsConfigurationServer(new Uri("Address"), credentials);
tfs.Authenticate();
详细的演练就在这里 。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.