当使用预编译的C#with attributes时,Azure函数中是否可能有多个out绑定?
当使用带属性的预编译C#函数时,Azure函数中是否可能有多个输出绑定 e、 一个函数在HTTP请求时触发,该函数同时响应HTTP响应和表存储当使用预编译的C#with attributes时,Azure函数中是否可能有多个out绑定?,azure,azure-functions,Azure,Azure Functions,当使用带属性的预编译C#函数时,Azure函数中是否可能有多个输出绑定 e、 一个函数在HTTP请求时触发,该函数同时响应HTTP响应和表存储 编辑:错误的目标,它是HTTP和Cosmos DB集合的文档是的,以下代码片段显示了此示例: #r "Newtonsoft.Json" #r "Microsoft.WindowsAzure.Storage" using System.Net; using Newtonsoft.Json; using System.Threading.Tasks; us
编辑:错误的目标,它是HTTP和Cosmos DB集合的文档是的,以下代码片段显示了此示例:
#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"
using System.Net;
using Newtonsoft.Json;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage.Table;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, CloudTable table, TraceWriter log)
{
log.Info("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;
// insert to the table
table.ExecuteAsync(TableOperation.Insert(new Request {PartitionKey=name, RowKey=Guid.NewGuid().ToString(), Body = JsonConvert.SerializeObject(data) }));
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);
}
public class Request : TableEntity
{
public string Body { get; set; }
}
虽然完全可以在单个函数中实现这一点,但您可能还想查看
最终,您将拥有多个小型功能。每个都在做自己的事情。下面是一个简单的函数示例,该函数具有两个输出绑定,使用最新的VS2017预览工具实现:
[函数名(“多重绑定”)]
公共静态HttpResponseMessage多输出绑定(
[HttpTrigger(AuthorizationLevel.Function,“post”)]HttpRequestMessage请求,
[队列(“输出队列”)]输出字符串队列项)
{
queueItem=“我的新队列消息”;
返回req.CreateResponse(HttpStatusCode.OK,“Hello”);
}
谢谢,这非常合适,因为我在VS2017预览版中使用了预编译的C。但我的错误是,我试图获得http响应并将文档写入Cosmos DB集合,而不是表。你知道这个属性吗,因为我在@SteveC中看不到任何东西,我不确定你要的是哪个属性DocumentDB
属性是Cosmos DB的属性。啊哈。。。助教。这正是我要寻找的,我试图设置属性,使其与“createdb和collection if not exists”复选框等效。。。哪个在DocumentDBAttribute.cs()中作为CreateIfNoteXistsSSO:您的1个输入绑定是HttpTrigger(标记为输入,因为它是“触发器”),然后您的2个输出绑定是Queue和HttpResponseMessage,对吗?队列在参数中指定,但HttpResponseMessage在返回类型中是隐式的?异步函数呢?他们无法使用out
params。链接已断开
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in"
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "table",
"type": "table",
"connection": "myStorage",
"tableName": "myTable",
"direction": "out"
}
],
"disabled": false
}