【问题标题】:Unable to connect to Azure DevOps Repo from C#无法从 C# 连接到 Azure DevOps Repo
【发布时间】:2020-09-27 12:34:03
【问题描述】:

我有一个 web api,它连接到 azure devops repo 并检索一些文件来执行一些操作。问题是,我无法从 Web 服务连接。我收到错误“SocketException:连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立连接失败,因为连接的主机没有响应”。但是,相同的代码在控制台应用程序中运行良好。

VssConnection connection = new VssConnection(new Uri("https://dev.azure.com/org"), new VssBasicCredential(string.Empty, "psa"));
TfvcHttpClient tfvcClient = connection.GetClient<TfvcHttpClient>(); //error here
string projectName = "Project";
string scopePath = $"$/{projectName}/";
List<TfvcItem> items = tfvcClient.GetItemsAsync(scopePath: scopePath, recursionLevel: VersionControlRecursionType.OneLevel).Result;
Console.WriteLine("Connection Established");

奇怪的是,一旦我通过控制台应用程序建立连接,如果我通过 Web 服务运行相同的代码,它就可以工作。我关闭了防火墙并检查了但没有任何效果。卡了这么久!

【问题讨论】:

  • 我无法重现上述问题。您可以尝试使用httpclient 调用tfvc rest api 而不是使用TfvcHttpClient。参见httpclient示例here
  • 我认为这是一个代理问题。我在 web.config 文件中启用了使用默认代理,它开始工作没有任何问题。这是我做的唯一改变。如果我禁用它,它就不起作用。对这种行为有一个解释会很棒。

标签: c# asp.net-web-api tfs azure-devops azure-repos


【解决方案1】:

经过几天的努力,在 web.config 中启用默认代理后,它运行良好:

<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
     <proxy usesystemdefault="True" />
</defaultProxy>

【讨论】:

  • 如果这是问题的答案,那么您可以将您的答案标记为已接受以帮助社区
猜你喜欢
  • 2021-10-27
  • 2020-04-23
  • 1970-01-01
  • 2020-01-12
  • 1970-01-01
  • 1970-01-01
  • 2021-11-17
  • 2019-09-25
  • 1970-01-01
相关资源
最近更新 更多