【问题标题】:Azure functions development and configuration with Azure SignalR Service throws an error message on connection string使用 Azure SignalR 服务的 Azure 函数开发和配置在连接字符串上引发错误消息
【发布时间】:2019-03-27 15:45:20
【问题描述】:

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

[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] 错误索引方法“协商”

[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>

所有这些似乎正确的配置都已到位,不知道为什么我们应该得到我上面引用的错误消息。

【问题讨论】:

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


    【解决方案1】:

    通过以下示例更新 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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-23
      • 2022-12-05
      • 1970-01-01
      • 1970-01-01
      • 2021-02-15
      • 1970-01-01
      相关资源
      最近更新 更多