1

Hope I can get the point across here..

I have 2 Workflows:

  1. (Test-Success) (c).NET WebAPI REST endpoint > (d)WebRequest to > (e)another .NET WebAPI REST endpoint > (f)Delphi.NET library
  2. (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);
Andrew Roberts
  • 990
  • 2
  • 12
  • 26

1 Answers1

0

Maybe there's a missing slash:

    client.BaseAddress = new Uri("http://localhost:xxxxx");
    client.DefaultRequestHeaders.Add("header1", "xxx");


    var uri = $"{client.BaseAddress}v1/CoreEndpoint";

=> http://localhost:xxxxxv1/CoreEndpoint

Does it work if you change it to:

    var uri = $"{client.BaseAddress}/v1/CoreEndpoint";
Markus Meyer
  • 3,327
  • 10
  • 22
  • 35
  • BaseAddress adds in the slash, but good spotting. In production HttpClient is added in startup like client.BaseAddress = new Uri($"{host}:{port}"); and then $"{_httpClient.BaseAddress}internal returns host/internal – Andrew Roberts Jul 02 '21 at 07:17