azure - 定义非常简单的手动 Azure 函数的返回

标签 azure azure-functions

我有一个 Azure 函数可以执行此操作:

public static int Run(int myvalue, TraceWriter log)
{
    log.Info($"C# manually triggered function called with input: {myvalue}");

    if (myvalue == 1) return 1;

    return (myvalue + 1);
}

我是直接在门户中创建的;但是,我对绑定(bind)的尝试可能是错误的:

{
  "bindings": [
    {
      "type": "manualTrigger",
      "direction": "in",
      "name": "myvalue"
    },
    {
      "type": "int",
      "direction": "out",
      "name": "$return"
    }
  ],
  "disabled": false
}

当我在门户内运行它时,它会给我一个 202(已接受),但不会输出函数的返回值。

我的问题基本上是,为什么我没有得到任何输出;然而,我想我的第一个问题应该是(是),我应该得到输出吗?如果是这样,我的绑定(bind)有什么问题吗?

这是一个稍微复杂的函数的简化版本,我打算将其用作逻辑应用程序内的条件(因此我需要一个返回值)。

最佳答案

int 不是手动触发支持的类型。您应该在日志中看到如下错误:

[Error] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ManualTriggerCSharp1'. Microsoft.Azure.WebJobs.Script: Can't bind ManualTriggerAttribute to type 'System.Int32'.

如果将参数类型更改为字符串,日志记录应该可以工作:

public static void Run(string myvalue, TraceWriter log)
{
    log.Info($"C# manually triggered function called with input: {myvalue}");
}

现在,从手动触发返回任何内容都没有意义。您可以继续返回 int 但它会被忽略。但删除第二个绑定(bind):

{
  "bindings": [
    {
      "type": "manualTrigger",
      "direction": "in",
      "name": "myvalue"
    }
   ],
   "disabled": false
 }

要返回值,您可能需要切换到 HTTP 触发器,从 HTTP 请求读取数据并返回 HTTP 响应。

关于azure - 定义非常简单的手动 Azure 函数的返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49017431/

相关文章:

c# - 我的服务应如何响应 Azure 负载均衡器探测?

Azure blob 返回 403 禁止在门户上运行的 Azure 函数

c# - Azure 服务总线的 Azure Function App 延迟重试

Azure Function PowerShell 检索和解析 HTTP POST 触发器正文

Azure 门户自定义磁贴 - Markdown 磁贴

typescript - Azure AD - MSAL.js - ssoSilent() 与 acquireTokenSilent()

azure - Azure 服务结构中的 EnableDefaultServicesUpgrade 未默认启用是否有原因

与托管 API 通信的 Javascript?

azure - 为什么 .NET 6 上的 Azure Function 寻找 System.ComponentModel 版本 6.0.0.0?

c# - 绑定(bind)到 CosmosDB 输入时需要“Id”