Azure Function REST API PUT returns 202 - c#

I have a REST API built in an Azure function. My PUT endpoints are returning the 202 async pattern, but all other endpoints are returning 200s.
This returns a 200 after updating the user's profile image
public async Task<IActionResult> PutProfileImage(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "profileimage")] HttpRequest req,
ILogger log)
This returns a 202 Accepted and never completes
[FunctionName("PutProfileImage")]
public async Task<IActionResult> PutProfileImage(
[HttpTrigger(AuthorizationLevel.Function, "put", Route = "profileimage")] HttpRequest req,
ILogger log)
Windows 10, VS 2019 16.9.4, Azure Functions V3, .NET Core 3.1. Happy to gather any more info that might help to understand this behavior.
Update 5/8/2021
This is a known issue being tracked here: https://github.com/Azure/Azure-Functions/issues/1878 and here https://github.com/Azure/azure-functions-host/issues/7260

If anyone else finds this, it's a known issue in the Azure Functions runtime. The issue being tracked here: https://github.com/Azure/Azure-Functions/issues/1878 and here https://github.com/Azure/azure-functions-host/issues/7260

Related

Webhook callback getting unexpected response 301 from Azure Function

I've created an Azure Function and hosted it in Azure. It accepts "post" and "get" requests and I can run this locally and get some log output when I either GET or POST to it.
When I host this in Azure, I can get the output the same if I do a GET or POST, which is what I expect (via postman).
I'm using a third party tool for a callback to my Azure Function URL. When this callback gets sent, I don't get any output in the Azure CLI for logs. It is using the exact same address as I was using to get my output in the portal.
The third party tool is saying its getting an HTTP 301 response.
Why would the callback be getting an HTTP 301 when I can post/get to the same address from Postman and get a 200 back?
Function code:
[FunctionName("AddressNotification")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation($"Address Callback function hit from req: {req.Host.ToString()}");
var content = await new StreamReader(req.Body).ReadToEndAsync();
log.LogInformation($"Request body: {content}");
return new OkResult();
}
Third party tool saying I'm getting a 301:
I would assume you have https only enabled in your function

Azure function HTTP Trigger not cancelling request

When I cancel my request from browser to a HTTP Trigger it does not cancel and continues execution when hosted on Azure.
My function example:
[FunctionName("Test")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
CancellationToken cancellationToken,
ILogger log)
{
var allCancellationTokens = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, req.HttpContext.RequestAborted);
await Task.Delay(30000, allCancellationTokens.Token);
if (allCancellationTokens.IsCancellationRequested) {
log.LogInformation("Request was cancelled!");
return new StatusCodeResult(499);
}
return new OkObjectResult("Complete");
}
I have been testing the cancellation through Postman and axios cancel tokens.
It works when I run the project locally and cancel it, but does not seem to cancel once it's published to azure.
My expected result would be that it throws an OperationCanceledException if I cancel the request during the await Task.Delay(30000, allCancellationTokens.Token); However when checking logs on Azure Functions, just seems to carry on execution and complete the function.
Steps to reproduce:
Create a HTTP Trigger like the one defined above.
Publish the app to Azure.
Open the functions logs on Azure in the monitor section.
Using Postman, send a request to this function and cancel the request (within the timeout period of 30 seconds).
Won't cancel the request and will still execute.
CancellationToken is helpful for implementing graceful shutdown of your Functions runtime host when it is notified by the Operating System that something has gone wrong to terminate it, please see the following answer for more: https://stackoverflow.com/a/63439515/528779

How to generate Azure function name based on the publish profile settings?

I have created HttpTrigger function, which generated code as below in Visual Studio
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
}
if you notice, the name of the function is Function1
Now, I have created the following publishing profiles, which deploys function on different Azure subscriptions.
dev-env-function1-profile
test-env-function1-profile
production-function1-profile
The issue is, it creates function name as Function1 in all the subscription, whereas we want have function name as follow for different environments.
Dev environment: devenv-function1
Test environment: testenv-function1
Production environment: function1
How can we set the function name dynamically?
[FunctionName("Function1")] <-- ???
Copy the answer provided by David.
Just use different names for the app in dev/test/production environment.

Azure Function V1 with WPF Controls

I tried to use Azure function v1 that contains some WPF controls. while Azure funtion v1 supports .Net framework, and it is supposed to work with windows environment. whenever the debugger reaches the WPF control, exception is being thrown shows that
"InvalidOperationException: The calling thread must be STA, because many UI components require this.
"
This is how my code looks like, I tested the function within browser.
[FunctionName("Report1")]
public static async Task<HttpResponseMessage> RunReport([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "hash/{hash1}")]HttpRequestMessage req, string hash1, TraceWriter log, Microsoft.Azure.WebJobs.ExecutionContext context){}
Dont have this usage method, Azure Function does not support UI. WPF controls should not be handled in Azure Functions.

Get a error with post API - Will not send JObject Toke to API?

hat's how I try to get POST some value over to my API. If I remove the "JObject Token", it works fine and then it does not give a fault 500.
But if it's on then it gives up 500.
Code has been taken from MVC over to .net core 2.0
How can I fix the problem so that my values can be submitted to the API?
ERROR HERE:
[Route("api/Stripe")]
[HttpPost]
public async Task<IActionResult> Post(JObject token)
NOT error here:
[Route("api/Stripe")]
[HttpPost]
public async Task<IActionResult> Post()
I have installed Newtonsoft.json in Nuget.
try with [FromBody] before your object.
i mean, something like this
[Route("api/Stripe")]
[HttpPost]
public async Task<IActionResult> Post([FromBody] JObject token)
i use [FromBody] to my apis on .Net, however, in .net core it seems that works the same
Json Post on ASP.NET CORE

Categories