预编译的Azure功能和CloudTable绑定输出不起作用

时间:2017-02-16 21:11:50

标签: c# azure azure-table-storage azure-functions

我正在使用预编译的Azure函数:

public static async Task Run(Stream inputBlob, Stream outputJson, Stream outputXml, CloudTable schedulerTable)

输出绑定看起来:

{
  "name": "schedulerTable",
  "type": "table",
  "direction": "out",
  "tableName": "SchedulerTable",
  "connection": "SchedulerTable"
}

当我从我的函数中删除参数schedulerTable时,它是有效的。 “主持人抛出的信息是:

Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.InputFileAdaptorAF'. Microsoft.Azure.WebJobs.Host: Can't bind Table to type 'Microsoft.WindowsAzure.Storage.Table.CloudTable'.

真的,当我添加一个表输出绑定尝试使用不同的替代品时,没有任何作用。不起作用的替代方案是:

  • 参数schedulerTable,类型为SchedulerRegister。 SchedulerRegister类继承自TableEntity。
  • 带有ICollector类型的参数schedulerTable。
  • 参数schedulerTable,类型为CloudTable。 (上述情况)。

拜托,¿我怎么能解决它? (使用输出绑定到azure表)

3 个答案:

答案 0 :(得分:11)

您可能遇到类型不匹配问题。您使用的是什么版本的存储SDK?您需要确保存储SDK引用与运行时期望的内容匹配,当前为7.2.1。

请确保您引用的是存储SDK版本7.2.1。

答案 1 :(得分:1)

根据你的描述,我已经测试了关于绑定到表输出的这个问题,我可以使它按预期工作。这是我的代码片段,您可以参考它。

<强> function.json

{
  "bindings": [
    {
      "name": "inputBlob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "input/{name}",
      "connection": "AzureStorageConnectionString"
    },
    {
      "type": "table",
      "name": "outTable",
      "tableName": "UploadFile",
      "connection": "AzureStorageConnectionString",
      "direction": "out"
    }
  ],
  "disabled": false
}
  • ICollector<T>
#r "Microsoft.WindowsAzure.Storage"

using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.WindowsAzure.Storage.Blob;

public static void Run(CloudBlockBlob inputBlob, ICollector<UploadFile> outTable, TraceWriter log)
{   
    string blobUri=inputBlob.StorageUri.PrimaryUri.ToString();
    log.Info($"C# Blob  trigger function triggered, blob path: {blobUri}");

    outTable.Add(new UploadFile()
    {
        PartitionKey = "Functions",
        RowKey = Guid.NewGuid().ToString(),
        Name = blobUri
    });
}

public class UploadFile : TableEntity
{
    public string Name { get; set; }
}
  • CloudTable
#r "Microsoft.WindowsAzure.Storage"

using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.WindowsAzure.Storage.Blob;

public static void Run(CloudBlockBlob inputBlob,CloudTable outTable, TraceWriter log)
{   
    string blobUri=inputBlob.StorageUri.PrimaryUri.ToString();
    log.Info($"C# Blob  trigger function triggered, blob path: {blobUri}");

    outTable.Execute(TableOperation.Insert(new UploadFile()
    {
        PartitionKey = "Functions",
        RowKey = Guid.NewGuid().ToString(),
        Name = blobUri
    }));
}

public class UploadFile : TableEntity
{
    public string Name { get; set; }
}

修改代码并单击保存,如果编译成功执行,则触发该功能时,您可以看到以下日志,并将记录添加到Azure表存储。

有关详细信息,请参阅此官方document有关Azure功能的存储表绑定。

答案 2 :(得分:1)

真的,这个答案来自Azure Functions的团队中的某个人(我不记得de name),在这个问题中,但他删除了她的回复。他说,问题肯定来自于预期的dll版本不同。我可以确认这是问题所在。

解决方案是检查AppData \ Local \ Azure.Functions.Cli \ 1.0.0-beta.91中使用的dll版本,并在解决方案中使用相同的版本。