6.30HttpLongPollingBuilder Builder

Created on Aug 17, 2026~2 min read

The HttpLongPollingBuilder builder provides the various settings the framework offers specifically for sending long polling requests. The HttpLongPollingBuilder constructor is private, so it cannot be instantiated directly with the new keyword; however, the framework provides several static overloads of HttpRequestBuilder.LongPolling to create an instance of HttpLongPollingBuilder.

cs
HttpRequestBuilder.LongPolling(httpMethod, requestUri, onDataReceived, configure);HttpRequestBuilder.LongPolling(requestUri, onDataReceived, configure); // Defaults to a GET requestHttpRequestBuilder.LongPolling(httpMethod, requestUri, configure);HttpRequestBuilder.LongPolling(requestUri, configure); // Defaults to a GET request

In addition, HttpLongPollingBuilder provides the following configuration capabilities:

cs
// Defaults to a GET requestHttpRequestBuilder.LongPolling("https://localhost:7044/HttpRemote/LongPolling"    , async (responseMessage, token) =>    {        Console.WriteLine(await responseMessage.Content.ReadAsStringAsync(cancellationToken));        await Task.CompletedTask;    })    // Sets the polling retry interval; default is 2 seconds    .SetRetryInterval(TimeSpan.FromSeconds(2))    // Sets the maximum number of retries; default is 100    .SetMaxRetries(500)    // Sets the operation for receiving data when the server returns a 200~299 status code    // .SetOnDataReceived(async responseMessage => {})  // Can be passed in at initialization    // Sets the operation for receiving data when the server returns a status code other than 200~299    .SetOnError(async responseMessage => {})    // Sets the operation triggered when the response headers contain X-End-Of-Stream    .SetOnEndOfStream(async ResponseMessage => {})    // Sets the long polling event handler    .SetEventHandler<CustomLongPollingEventHandler>()    .SetEventHandler(typeof(CustomLongPollingEventHandler))    // Sets the HttpRequestBuilder instance    .With(builder => {}));  // Supports further extensions

After successfully building an HttpLongPollingBuilder instance through the HttpRequestBuilder.LongPolling method, you can use Send, SendAsync, or SendAsAsyncEnumerable to perform the send operation.

cs
httpRemoteService.Send(httpLongPollingBuilder, cancellationToken);await httpRemoteService.SendAsync(httpLongPollingBuilder, cancellationToken);await foreach (var response in httpRemoteService.SendAsAsyncEnumerable(httpLongPollingBuilder, cancellationToken)){    // Process each response}