c# - 如何以编程方式触发 azure 函数在 C# 代码中运行?

标签 c# azure azure-functions

我要编写一个集成测试,其中涉及手动运行一个函数,相当于在 Azure 中的计时器触发器上按此按钮...

enter image description here

这可以在 C# 中从单独的代码库到函数代码本身以编程方式完成吗?目前我无法访问功能代码,但可以访问azure。

或者,我可以通过代码更新计划以便立即触发吗?

到目前为止,我一直在努力寻找一种通过某种 sdk、API 调用或 powershell 脚本来完成此操作的方法。希望我遗漏了一些明显的东西

非常感谢,

最佳答案

您可以创建 HTTP trigger并从 C# 代码中调用它。

示例代码:

[FunctionName("HttpTriggerCSharp")]
public static async Task<HttpResponseMessage> Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, 
    ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    // parse query parameter
    string name = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
        .Value;

    // Get request body
    dynamic data = await req.Content.ReadAsAsync<object>();

    // Set name to query string or body data
    name = name ?? data?.name;

    return name == null
        ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
        : req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}

关于c# - 如何以编程方式触发 azure 函数在 C# 代码中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54540434/

相关文章:

c# - 程序集 '' 中的类型 '' 未标记为可序列化。 linq-to-sql

c# - 如何使用 log4net 存储在数据库中了解当前日志级别

azure - Microsoft Azure EventHub 中的事件保留

c# - 如何在触发器属性中基于 dotnet core 的 Azure 函数中读取 settings.json 中的配置值

node.js - 正确的 Jest 测试 Azure Functions

Azure函数: during zip deployment,有没有一种方便的方法来完全删除 `wwwroot`中的旧内容?

c# - 如何从 Controller 中的局部 View 获取html

c# - 更改链接按钮颜色

security - 为什么对 Azure Blob 存储使用 HTTPS

azure - Windows 镜像组件的版本