这是我使用的代码。几天它正常工作,但突然停止工作。
var TFS_UserName = "UserName";
var TFS_Pass = "Password";
var domain = "domain";
var tfsUri = System.Configuration.ConfigurationManager.AppSettings["TFSUri"];
Uri uri = new Uri(tfsUri);
NetworkCredential cred = new NetworkCredential(TFS_UserName, TFS_Pass, domain);
BasicAuthCredential basicCred = new BasicAuthCredential(cred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(uri, tfsCred);
try
{
tpc.Authenticate();
}
catch (Exception ex)
{
return "User not Authorized" + ex.Message;
}
var vcServer = (VersionControlServer)tpc.GetService(typeof(VersionControlServer));
var LocalPath = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["FileSave"]);
var tempAddress = "File Path";
var i = vcServer.GetItem(@"$/Folder/Path/" + tempAddress + "/" + "FileName");
i.DownloadFile(LocalPath + "FileName");
此代码突然开始在 tpc.Authenticate();
处引发异常例外是: TF400324:服务器https://tfs/Address无法使用Team Foundation服务。 技术信息(针对管理员): 基础连接已关闭:发送中发生意外错误。
前来源:Microsoft.TeamFoundation.Client
内部Ex:基础连接已关闭:发送中发生意外错误。
{内部Ex:无法从传输连接中读取数据:现有连接被远程主机强行关闭。}
答案 0 :(得分:0)
也许基本身份验证在解决问题,请尝试通过这种方式连接:
var TFS_UserName = "UserName";
var TFS_Pass = "Password";
var domain = "domain";
var tfsUri = System.Configuration.ConfigurationManager.AppSettings["TFSUri"];
Uri uri = new Uri(tfsUri);
NetworkCredential cred = new NetworkCredential(UserName, Password);
TfsTeamProjectCollection tfsCollection = new TfsTeamProjectCollection(tfsUri, cred);
try
{
tfsCollection.EnsureAuthenticated();
}
catch (Exception ex)
{
return "User not Authorized" + ex.Message;
}
答案 1 :(得分:0)
首先,必须确保可以在运行代码的计算机上的Web门户中访问TFS。
然后,尝试清除运行该代码的计算机上的Cache文件夹。文件夹路径为:C:\Users\username\AppData\Local\Microsoft\Team Foundation\x.0\Cache
。
此外,尝试删除与Control Panel\All Control Panel Items\Credential Manager
中的TFS相关的Windows凭据。