csh*_*aml 5 c# web-services tfs-sdk azure-devops
我如何向 提供凭据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);
Run Code Online (Sandbox Code Playgroud)
第二次尝试使用从 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)
{
}
}
Run Code Online (Sandbox Code Playgroud)
但它只在我的机器上工作,因为我登录了 tfs.
为了避免系统提示您使用 Live ID 登录或必须已登录,您需要启用备用登录凭据并将其用于您的服务。
这篇博文告诉您如何:
请注意,您需要安装 VS 2012 Update 1 才能使用此功能。
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
17718 次 |
| 最近记录: |