您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Using the Azure Function return valueUsing the Azure Function return value

This article explains how return values work inside a function.This article explains how return values work inside a function.

In languages that have a return value, you can bind a function output binding to the return value:In languages that have a return value, you can bind a function output binding to the return value:

  • 在 C# 类库,请将输出绑定特性应用到方法返回值。In a C# class library, apply the output binding attribute to the method return value.
  • 在其他语言中,请将 function.json 中的 name 属性设置为 $returnIn other languages, set the name property in function.json to $return.

如果有多个输出绑定,请只使用其中一个绑定的返回值。If there are multiple output bindings, use the return value for only one of them.

在 C# 和 C# 脚本中,将数据发送到输出绑定的替代方法是使用 out 参数和收集器对象In C# and C# script, alternative ways to send data to an output binding are out parameters and collector objects.

以下 C# 代码使用输出绑定的返回值,后接异步示例:Here's C# code that uses the return value for an output binding, followed by an async example:

[FunctionName("QueueTrigger")]
[return: Blob("output-container/{id}")]
public static string Run([QueueTrigger("inputqueue")]WorkItem input, ILogger log)
{
    string json = string.Format("{{ \"id\": \"{0}\" }}", input.Id);
    log.LogInformation($"C# script processed queue message. Item={json}");
    return json;
}
[FunctionName("QueueTrigger")]
[return: Blob("output-container/{id}")]
public static Task<string> Run([QueueTrigger("inputqueue")]WorkItem input, ILogger log)
{
    string json = string.Format("{{ \"id\": \"{0}\" }}", input.Id);
    log.LogInformation($"C# script processed queue message. Item={json}");
    return Task.FromResult(json);
}

后续步骤Next steps