【发布时间】: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