Web Services 从Web服务连接到Visual Studio团队服务

ztigrdn8  于 2022-11-15  发布在  其他
关注(0)|答案(2)|浏览(190)

如何向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。

nkhmeac6

nkhmeac61#

为避免提示您使用Live ID登录或必须先登录,您需要启用备用登录凭据并将其用于您的服务。
这篇博客文章告诉您如何:
http://blogs.msdn.com/b/buckh/archive/2013/01/07/how-to-connect-to-tf-service-without-a-prompt-for-liveid-credentials.aspx
请注意,您需要安装VS 2012 Update 1才能拥有此功能。
希望这对你有帮助。

6psbrbz9

6psbrbz92#

我最近,找到了这个解决办法:

NetworkCredential netCred = new NetworkCredential(user,pass);

BasicAuthCredential basicCred = new BasicAuthCredential(netCred);

TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);

tfsCred.AllowInteractive = false;

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(path), TFSCred);

相关问题