Hello @sunny - Thanks for providing the details via comments. I tried a similar use case (on .NET8 isolated-worker) and have configured the following where the HttpClient
is added via DI and tested by using it to download a .csv
file data from an HTTP endpoint:
Program.cs
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
services.AddHttpClient();
})
.Build();
host.Run();
Function1.cs
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.DurableTask;
using Microsoft.DurableTask.Client;
using Microsoft.Extensions.Logging;
namespace FunctionApp8
{
public class Function1
{
private readonly HttpClient httpClient;
public Function1(IHttpClientFactory factory)
{
httpClient = factory.CreateClient();
}
[Function(nameof(Function1))]
public static async Task<List<string>> RunOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
ILogger logger = context.CreateReplaySafeLogger(nameof(Function1));
logger.LogInformation("Saying hello.");
var outputs = new List<string>();
// Replace name and input with values relevant for your Durable Functions Activity
outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "Tokyo"));
return outputs;
}
[Function(nameof(SayHello))]
public async Task<string> SayHello([ActivityTrigger] string name, FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("SayHello");
logger.LogInformation("Saying hello to {name}.", name);
using HttpResponseMessage response = await httpClient.GetAsync("https://murnunstorage.blob.core.windows.net/subfolder/Integration.csv");
string responseBody = await response.Content.ReadAsStringAsync();
return responseBody;
}
[Function("Function1_HttpStart")]
public static async Task<HttpResponseData> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
[DurableClient] DurableTaskClient client,
FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("Function1_HttpStart");
// Function input comes from the request content.
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
nameof(Function1));
logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);
// Returns an HTTP 202 response with an instance management payload.
// See https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-http-api#start-orchestration
return client.CreateCheckStatusResponse(req, instanceId);
}
}
}
The above is of the same structure as yours (Http starter -> Orchestration -> Activitiy), and after the Activity function is run, I confirmed successful access to the response (downloaded contents of the remote file):
Could you try the same way as above and let us know if it helps accomplish your use case? I look forward to your reply.
Please "Accept Answer" if the answer is helpful so that others in the community may benefit from your experience.