Skip to main content
1-Visitor
July 30, 2021
Question

A connection attempt failed because the connected party did not properly respond

  • July 30, 2021
  • 1 reply
  • 7010 views

I have a functionality to call Windchill rest services from my web application. I am doing this in c#.net code

My Code

using (var client = new HttpClient())
 {
 client.DefaultRequestHeaders.Accept.Add(new 
 MediaTypeWithQualityHeaderValue("application/json"));

 var byteArray = Encoding.ASCII.GetBytes("abc:defg!");

 client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

 client.DefaultRequestHeaders.Add("CSRF_NONCE", a.NonceValue);

 var message = await client.PostAsync("hostname/Windchill/servlet/odata/v3/ProdMgmt/Parts('OR:wt.part.WTPart:123456')/PTC.ProdMgmt.GetPartStructure?$expand=Components($select=PartName,PartNumber;$expand=PartUse($select=FindNumber,LineNumber,Quantity,Unit);$levels=1)", null);
 }
  1. I can call it successfully from my local machine but when I try to call it after deploying to the Test server (Windows Server), I get the below error.

System.Net.Http.HttpRequestException: 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. ---> System.Net.Sockets.SocketException (10060): 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. at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Sockets.Socket.g__WaitForConnectWithCancellation|283_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.DefaultConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellationToken) at System.Net.Http.ConnectHelper.ConnectAsync(Func3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.ConnectAsync(Func3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)

 

I tried adding different options to the code but nothing have worked.

 

Any help is much appreciated.

1 reply

17-Peridot
October 6, 2021

Hi SC,

Is your authentication valid?

Or is it possible that you are getting a 503? I get that occasionally.

 

Try looping with a delay of one second, and a limit of five loops. This works for me, and I have not seen more than one 503 before a valid answer is returned.

YMMV -- Rick