如何向TfsTeamProjectCollectionFactory.GetTeamProjectCollection
提供凭据?
我正在尝试开发自己的WCF服务,从中向TFS发出请求
我需要这个WCF服务,因为我想管理我的TFS文件,而我不能在移动设备上使用Microsoft.TeamFoundation.* dll
我一直在尝试这种方法
Uri tpcAddress= new Uri("https://myserver.visualstudio.com/DefaultCollection");
TfsConnection tfsc = new TfsConfigurationServer(tpcAddress,
new NetworkCredential("mail@example.com", "password"));
TfsWebClient wc = new TfsWebClient(tfsc);
tfsc.Connect(ConnectOptions.IncludeServices);
第二次尝试使用从ICredentialsProvider派生的自定义类
ICredentialsProvider prov = new myCredentials();
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcAddress, prov);
tpc.EnsureAuthenticated();
tpc.Authenticate();
public class myCredentials : ICredentialsProvider
{
public ICredentials GetCredentials(Uri uri, ICredentials failedCredentials)
{
return new NetworkCredential("mail@example.com", "password");
}
public void NotifyCredentialsAuthenticated(Uri uri)
{
}
}
但这只在我的机器上有效,因为我已登录到TFS。