使用Azure SignalR Service开发和配置Azure功能会在连接字符串上引发错误消息

时间:2019-03-27 15:45:20

标签: signalr azure-functions signalr-hub azure-functions-runtime azure-signalr

这是该函数的代码,非常简单:

[FunctionName("negotiate")]
        public static SignalRConnectionInfo Run(
            [HttpTrigger(AuthorizationLevel.Anonymous)]
            HttpRequest req,
            [SignalRConnectionInfo(
            ConnectionStringSetting = "Endpoint=https://myowntestserver.service.signalr.net;AccessKey=mymaskedaccesskey=;Version=1.0;",
            HubName = "tracking")]
            SignalRConnectionInfo connectionInfo)
        {            
            return connectionInfo;
        }

在Visual Studio 2017上运行此代码时,出现以下错误消息:

  

[2019-03-27 3:39:14 PM]错误索引方法'negotiate'

     

[2019-03-27 3:39:14 PM] Microsoft.Azure.WebJobs.Host:错误索引方法   '谈判'。 Microsoft.Azure.WebJobs.Host:无法解析该值   属性“ SignalRConnectionInfoAttribute.ConnectionStringSetting”。   确保设置存在并且具有有效值。

local.settings.json文件如下:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}

这是host.json文件:

{
    "version": "2.0"
}

项目文件包含以下nuget包:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="3.0.3" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.SignalRService" Version="1.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.26" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

在所有这些看起来正确的配置之后,不确定为什么我们会收到上面引用的错误消息。

1 个答案:

答案 0 :(得分:0)

通过按照以下示例更新local.settings.json文件来解决此问题:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
    "AzureSignalRConnectionString": "Endpoint=Endpoint=https://myowntestserver.service.signalr.net;AccessKey=mymaskedaccesskey=;Version=1.0;""
  },
  "Host": {
    "LocalHttpPort": 7071,
    "CORS": "*"
  }
}

此外,应从属性中删除SignalRConnectionInfo.ConnectionStringSetting。