【问题标题】:Default Durable Function errors out with Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'starter'Microsoft.Azure.WebJobs.Host 出现默认持久函数错误:无法绑定参数“starter”
【发布时间】:2020-02-04 19:54:03
【问题描述】:

我刚开始使用 Azure 函数,特别是持久函数。

我在 https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-create-first-csharp 工作

我添加了一个新的 azure 持久函数,默认代码如下所示。

我看到我的库是持久函数版本 2,所以我必须对类名进行一些更改才能解析(链接在上面讨论更改的链接中):

    [FunctionName("TestFunction")]
    public static async Task<List<string>> RunOrchestrator(
        [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
        var outputs = new List<string>();

        // Replace "hello" with the name of your Durable Activity Function.
        outputs.Add(await context.CallActivityAsync<string>("TestFunction_Hello", "Tokyo"));
        outputs.Add(await context.CallActivityAsync<string>("TestFunction_Hello", "Seattle"));
        outputs.Add(await context.CallActivityAsync<string>("TestFunction_Hello", "London"));

        // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
        return outputs;
    }

    [FunctionName("TestFunction_Hello")]
    public static string SayHello([ActivityTrigger] string name, ILogger log)
    {
        log.LogInformation($"Saying hello to {name}.");
        return $"Hello {name}!";
    }

    [FunctionName("TestFunction_HttpStart")]
    public static async Task<HttpResponseMessage> HttpStart(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")]HttpRequestMessage req,
        [OrchestrationClient]IDurableOrchestrationClient starter, ILogger log)
    {
        // Function input comes from the request content.
        string instanceId = await starter.StartNewAsync("TestFunction", null);

        log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

        return starter.CreateCheckStatusResponse(req, instanceId);
    }

当我在本地运行它时,它会启动存储模拟器,但随后出现几个错误:

Microsoft.Azure.WebJobs.Host:索引方法“TestFunction_HttpStart”出错。 Microsoft.Azure.WebJobs.Host:无法将参数“starter”绑定到类型 IDurableOrchestrationClient。确保绑定支持参数类型。如果您正在使用绑定扩展(例如 Azure 存储、ServiceBus、计时器等),请确保您已在启动代码中调用了扩展的注册方法(例如 builder.AddAzureStorage()、builder.AddServiceBus( )、builder.AddTimers() 等)。

Microsoft.Azure.WebJobs.Host:索引方法“TestFunction_HttpStart”出错。 Microsoft.Azure.WebJobs.Host:无法将参数“starter”绑定到类型 IDurableOrchestrationClient。确保绑定支持参数类型。如果您正在使用绑定扩展(例如 Azure 存储、ServiceBus、计时器等),请确保您已在启动代码中调用了扩展的注册方法(例如 builder.AddAzureStorage()、builder.AddServiceBus( )、builder.AddTimers() 等)。

为什么这些错误会从默认测试代码中显示出来,我该如何解决?

【问题讨论】:

    标签: azure-functions


    【解决方案1】:

    您错过了将DurableClient 中提到的DurableClient 属性更改为1.x 中的OrchestrationClientAttribute2.x 中的DurableClientAttribute

    【讨论】:

      猜你喜欢
      • 2020-04-05
      • 2019-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-28
      • 2017-04-27
      相关资源
      最近更新 更多