Hi
I need to call one function in another function in azure function app using c#.
please help
Hi
I need to call one function in another function in azure function app using c#.
please help
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mohammad HussainRank #513 · 4.8K reputationPosted Jul 31, 2023, 10:40 AM EDT
// Function1.cs using System.Net.Http; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.AspNetCore.Http; public static class Function1 { [FunctionName("Function1")] public static async Task Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req) { // Call Function2 using an HTTP request using (var client = new HttpClient()) { var function2Url = "https://your-function-app-url/api/Function2"; var response = await client.GetAsync(function2Url); } // Other logic for Function1 return new OkResult(); } } // Function2.cs using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.AspNetCore.Http; public static class Function2 { [FunctionName("Function2")] public static async Task Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req) { // Logic for Function2 return new OkResult(); } }Tahir AnsariRank #366 · 6.8K reputationPosted Jul 31, 2023, 10:23 AM EDT
using Microsoft.Azure.WebJobs; using Microsoft.Extensions.Logging; public static class MyFunctions { [FunctionName("FunctionA")] public static async Task RunFunctionA( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ExecutionContext context, ILogger log) { // Your logic for FunctionA // Call FunctionB await RunFunctionB(req, context, log); // Continue with FunctionA logic or return a response return new OkResult(); } [FunctionName("FunctionB")] public static async Task RunFunctionB( HttpRequest req, ExecutionContext context, ILogger log) { // Your logic for FunctionB } }Cr BhargaviRank #420 · 5.9K reputationPosted Jul 31, 2023, 9:36 AM EDT
In Azure Function Apps using C#, you can call one function from another function within the same Function App. You can achieve this by using either a direct method call or by triggering the second function as an HTTP request.Example of calling direct function
public static class MyFunctions
{
[FunctionName("Function1")]
public static void RunFunction1([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log)
{
// Function1 logic here
// Call Function2
Function2();
}
public static void Function2()
{
// Function2 logic here
}
}
Function1is a TimerTrigger function that gets triggered every 5 minutes. InsideFunction1, we callFunction2directly.