-1

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

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

有了所有这些看起来正确的配置,不知道为什么我们应该得到我上面引用的错误消息。

4

1 回答 1

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。

于 2019-03-27T19:05:55.970 回答