Adjusting Connection Timeout in BlazorComponentBase

How can I adjust the timeout from the default (100s) for the JsonApiClient Client obtained from BlazorComponentBase (i.e.ServiceStack.Blazor.BlazorComponentBase)?

I would like to know how to make 2 types of adjustments:

  1. For all requests (i.e. change the default)
  2. For specific requests (i.e. override the default)

My applications are NET Core using Blazor WASM and ServiceStack 6.9.0 (under Windows).

Any help appreciated.

You’d should be able to set it on the underlying HttpClient.Timeout property.

For all clients you can configure in the HttpClient factory in Program.cs:

    httpClient => httpClient.Timeout = timeout);

For a single Page/component you can access the underlying HttpClient instance used with:

protected override async Task OnInitializedAsync()
    base.Client.GetHttpClient().Timeout = timeout;

I tried both the above, by reducing the timeout to only 10 seconds; expecting services to fail accordingly.

The services took longer than 10 seconds and did not timeout, which suggest that the 100 second default was not being adjusted.

That’s the only way to configure the HttpClient with a Timeout, but in WASM HttpClient is just a wrapper around the browser’s fetch API, so maybe it doesn’t implement HttpClient’s Timeout functionality properly.

I managed to increase the timeout by ensuring the client is used and not the Gateway:

// adjust to more than 100s default
var timeout =TimeSpan.FromSeconds(200);
Client.GetHttpClient().Timeout = timeout;
UseGateway = false;

Unfortunately, I receive intermittent “Bad Gateway” responses with the above code, which have proven impossible to debug. So, I no longer recommend the above to increase the HTTP timeout.