0

I have a web api which connects to azure devops repo and retrieves some files to do some operations. Problem is, I am unable to connect from the web service. I get the error "SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond". However, the same code runs perfectly fine in a console application.

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");

Strangely, once I establish connection through the console application, if I run the same code through the web service, it works. I turned off firewall and checked but nothing works. Been stuck for so long!

GBouffard
  • 1,125
  • 4
  • 11
  • 24
  • I cannot reproduce above issue. You can have a try using `httpclient` to call [tfvc rest api](https://learn.microsoft.com/en-us/rest/api/azure/devops/tfvc/items/list?view=azure-devops-rest-5.1#a-folder-and-its-children) instead of using `TfvcHttpClient`. See httpclient example [here](https://learn.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-5.1#assemble-the-request) – Levi Lu-MSFT Jun 09 '20 at 09:27
  • I think this is a proxy issue. I enable using default proxy in the web.config file and it started working without any issue. That is the only change I did. If I disable it, it is not working. Would be great to have an explanation for this behavior. – littlemisslilycane Jun 09 '20 at 14:57

1 Answers1

0

After struggling to make it work for few days, it worked fine after enabling the default proxy in web.config:

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

</system.net>