Hope I can get the point across here..
I have 2 Workflows:
- (Test-Success) (c).NET WebAPI REST endpoint > (d)WebRequest to > (e)another .NET WebAPI REST endpoint > (f)Delphi.NET library
- (Fails): (a)ASP.NET 5 Core REST endpoint > (b)HttpClient.SendAsync > (c)WebAPI REST endpoint> (d)WebRequest to > (e)another .NET WebAPI REST endpoint > (f)Delphi.NET library (blocks when calling the underlying Delphi method)
(2) is target state. From (c) onwards, it exactly the same as 1).
- In (2) Fiddler shows that correct url/headers are passed at (c) to the .WebAPI REST endpoint - but it never returns until the ASP.NET Core call (b) times out.
Things tried (not exhaustive)
- added ConfigureAwait(false) all way down the stack
- rewriting .NET Framework code to use HttpClient
- adding Async in the code calling Delphi.NET
- Removing async in HttpClient calls
- Adding EnableCors in Startup for the final endpoint
- Tried increasing and decreasing timeouts (on client and server)
- ConsoleApp to simplify the process
Standard Code to use HttpClient
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:xxxxx");
client.DefaultRequestHeaders.Add("header1", "xxx");
var uri = $"{client.BaseAddress}v1/CoreEndpoint";
string jsonContent = JsonConvert.SerializeObject("{body}");
var m = new HttpRequestMessage { RequestUri = new Uri(uri), Method = HttpMethod.Post };
m.Content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.SendAsync(m);