3

I have the basic durable function code:

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);
        }
    }
}

what i would like to achieve is to call the http trigger with passing the parameter name like that: http://localhost:7071/api/Function1_HttpStart?name=Josh

and then pass the parameter from http trigger, to orchestrator and finally to the activity called by orchestrator.

Right now in this code, the output is Saying hello to . so it looks like it doesn't pass the parameter through the code, or the parameter is not being read from the request url.

Is there any way to achieve this?

1

1 Answer 1

4

You can use the following code to receive name:

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

The following code is used to receive the request body in the post request, it cannot receive the parameters in the get request.

    var content = req.Content;
    string jsonContent = content.ReadAsStringAsync().Result;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, i just passed the parameter in the request body as a simple json :) That worked!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.