Azure功能不起作用VS2017

时间:2017-10-04 17:14:45

标签: azure visual-studio-2017 azure-functions azure-functions-runtime

我已经下载了VS2017社区版以试用Azure功能,但我无法使用它。我在Stackoverflow和Azure函数Github页面上搜索过很多帖子,但似乎没有任何关于任何内容的完整文档。

这就是我所拥有的:

Azure功能:

namespace FunctionApp1
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([ServiceBusTrigger("ngctestqueue", AccessRights.Manage, Connection = "Endpoint=sb://ngcservicebus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SERVICE_BUS_KEY")]string myQueueItem, TraceWriter log)
        {
            log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
        }
    }
}

host.json

{
  "disabled": false,
  "bindings": [
    {
      "name": "myQueueItem",
      "type": "serviceBusTrigger",
      "direction": "in",
      "queueName": "ngctestqueue",
      "connection": "connection",
      "accessRights": "manage"
    }
  ]
}

local.settings.json

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=ngctest2;AccountKey=STORAGE_ACCOUNT_KEY;EndpointSuffix=core.windows.net",
    "AzureWebJobsDashboard": "DefaultEndpointsProtocol=https;AccountName=ngctest2;AccountKey=STORAGE_ACCOUNT_KEY;EndpointSuffix=core.windows.net",
    "AzureWebJobsServiceBus": "Endpoint=sb://ngcservicebus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SERVICE_BUS_KEY",
    "connection": "Endpoint=sb://ngcservicebus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SERVICE_BUS_KEY"
  }
}

当我在本地通过F5运行该功能时,出现以下错误:

Microsoft.Azure.WebJobs.Host: Error indexing method 'Func
tion1.Run'. Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK Serv
iceBus connection string 'AzureWebJobsEndpoint=sb://ngcservicebus.servicebus.win
dows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SERVICE_BUS_KEY' is missing or empty.

我的开发环境如下:

1)Windows 8.1 Pro

2)VS2017社区15.3.5

3)Azure Functions CLI 1.0.4

真的很感激任何帮助。

谢谢。

1 个答案:

答案 0 :(得分:1)

Connection属性应设置为连接字符串名称,而不是值本身。然后将从配置中读取该值。

[ServiceBusTrigger("ngctestqueue", AccessRights.Manage, Connection = "AzureWebJobsServiceBus")]

您不需要在本地环境中创建host.json(它将由SDK自动生成)。