Reputation: 238
I am trying to use Azure Durable Functions to pass an HttpRequestMessage, received from the Http Triggered function, into another function as follows:
[FunctionName("RequestHandler")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, methods: new string[] {"get", "post"}, Route = "RequestHandler")]
HttpRequestMessage request,
[DurableClient] IDurableOrchestrationClient orchestrationClient,
ILogger logger)
{
var instanceId = await orchestrationClient.StartNewAsync<HttpRequestMessage>("MakeCallout", request);
return new AcceptedResult("", "");
}
[FunctionName("MakeCallout")]
public static async Task RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext context,
ILogger logger)
{
HttpRequestMessage request = context.GetInput<HttpRequestMessage>();
}
But I am getting an exception in Newtonsoft at runtime, I presume since durable functions uses the Json Seralization to pass data between functions:
System.Private.CoreLib: Exception while executing function: RequestHandler. Newtonsoft.Json: Self referencing loop detected for property 'Engine' with type 'Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine'. Path 'Properties.HttpContext.ServiceScopeFactory.Root'.
Is there a way of getting around this and passing the request message in without copying the data to another object and then passing in?
Upvotes: 1
Views: 2011
Reputation: 384
You should pass a JSON-serializeable value to the Orchestrator.
[FunctionName("RequestHandler")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, methods: new string[] {"get", "post"}, Route = "RequestHandler")]
HttpRequestMessage request,
[DurableClient] IDurableOrchestrationClient orchestrationClient,
ILogger logger)
{
dynamic data = await req.Content.ReadAsAsync<object>(); // if you have some json data in your http request's body. Or use req.Content.ReadAsStringAsync()
var instanceId = await orchestrationClient.StartNewAsync("MakeCallout", data);
return new AcceptedResult("", "");
}
Upvotes: 2
Reputation: 58853
You need to read the request in your HTTP function and send a serializable object to the orchestrator. Define a class that contains the data you need in the orchestrator. Like TheGeneral mentioned in the comment, serializing an HttpRequestMessage is most likely impossible.
Why is this needed? Because Durable Functions will store the input object as JSON in Table Storage. The orchestrator function reads it from there.
Upvotes: 2