我有一个 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/