通过 URL 请求将参数传递给 azure 持久函数

Passing parameter to azure durable function via URL Request

我有基本耐用功能代码:

namespace dotNetDurableFunction
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<List<string>> RunOrchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context)
        {
            var outputs = new List<string>();
            string name = context.GetInput<string>();

            // Replace "hello" with the name of your Durable Activity Function.
            outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", name));

            return outputs;
        }

        [FunctionName("Function1_Hello")]
        public static string SayHello([ActivityTrigger] string name, ILogger log)
        {
            log.LogInformation($"Saying hello to {name}.");
            return $"Hello {name}!";
        }

        [FunctionName("Function1_HttpStart")]
        public static async Task<HttpResponseMessage> HttpStart(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
            [DurableClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            //var name = await req.Content.ReadAsStringAsync();
            var name = "Bart";
            log.LogInformation(name);
            // Function input comes from the request content.
            string instanceId = await starter.StartNewAsync("Function1", name);

            log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

            return starter.CreateCheckStatusResponse(req, instanceId);
        }
    }
}

我想要实现的是通过传递参数 name 来调用 http 触发器,如下所示: http://localhost:7071/api/Function1_HttpStart?name=Josh

然后将参数从 http 触发器传递到 orchestrator,最后传递给 orchestrator 调用的 activity。

现在在这段代码中,输出是 Saying hello to .,所以看起来它没有通过代码传递参数,或者没有从请求 url 中读取参数。

有什么办法可以实现吗?

您可以使用以下代码接收姓名:

    var name = req.RequestUri.Query.Split("=")[1];

以下代码用于接收post请求中的请求体,无法接收get请求中的参数。

    var content = req.Content;
    string jsonContent = content.ReadAsStringAsync().Result;