如何将函数应用程序与 SharePoint webhook 结合使用?

How can I use function app with SharePoint webhook?

我正在使用函数应用程序处理 SharePoint webhook。我正在使用 Using Azure Functions with SharePoint webhooks[参考]。我使用函数应用程序在 Microsoft azure 上创建了一个函数,其中我得到的默认代码如下:

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
 {
    log.LogInformation("C# HTTP trigger function processed a request.");
    string name = req.Query["name"];
    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

    return name != null
    ? (ActionResult)new OkObjectResult($"Hello, {name}")
    : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}

然后我用参考的运行()中给出的代码替换了给定的函数代码。我尝试 运行 该程序,但它给了我以下错误:

2020-02-05T07:40:16.362 [Error] Function compilation error
Microsoft.CodeAnalysis.Scripting.CompilationErrorException : Script compilation failed.
   at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.CreateFunctionTarget(CancellationToken cancellationToken) at D:\a\s\src\WebJobs.Script\Description\DotNet\DotNetFunctionInvoker.cs : 314
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Script.Description.FunctionLoader`1.GetFunctionTargetAsync[T](Int32 attemptCount) at D:\a\s\src\WebJobs.Script\Description\FunctionLoader.cs : 55
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.GetFunctionTargetAsync(Boolean isInvocation) at D:\a\s\src\WebJobs.Script\Description\DotNet\DotNetFunctionInvoker.cs : 183
2020-02-05T07:40:16.580 [Warning] run.csx(11,62): warning CS0618: 'TraceWriter' is obsolete: 'Will be removed in an upcoming version. Use Microsoft.Extensions.Logging.ILogger instead.'
2020-02-05T07:40:16.632 [Error] run.csx(16,34): error CS1061: 'HttpRequestMessage' does not contain a definition for 'GetQueryNameValuePairs' and no accessible extension method 'GetQueryNameValuePairs' accepting a first argument of type 'HttpRequestMessage' could be found (are you missing a using directive or an assembly reference?)
2020-02-05T07:40:16.757 [Error] run.csx(47,19): error CS1061: 'CloudQueue' does not contain a definition for 'CreateIfNotExists' and no accessible extension method 'CreateIfNotExists' accepting a first argument of type 'CloudQueue' could be found (are you missing a using directive or an assembly reference?)
2020-02-05T07:40:16.821 [Error] run.csx(52,19): error CS1061: 'CloudQueue' does not contain a definition for 'AddMessage' and no accessible extension method 'AddMessage' accepting a first argument of type 'CloudQueue' could be found (are you missing a using directive or an assembly reference?)
2020-02-05T07:40:16.918 [Error] Executed 'Functions.HttpTrigger1' (Failed, Id=36875311-6d8e-496a-989b-1ac16ce39f5a)
Script compilation failed.

我不知道我在按照参考资料中给出的步骤操作时做错了什么。我该如何纠正这个错误并设置一个函数来获取 SharePoint 网站的通知?

您引用的示例是函数 运行-time V1,当您从中创建新函数时,它将指向 运行time V3。为了 运行 与您需要将函数 运行time 降级到 V1 并使用来自 document

的代码

为了将函数 运行time 降级到 v1,您需要浏览到 Azure Function Portal --> Platform Features --> Configuration

FUNCTIONS_EXTENSION_VERSION 指向 ~1 并删除 FUNCTIONS_WORKER_RUNTIME 应用程序设置。

参考文档:https://docs.microsoft.com/en-us/azure/azure-functions/set-runtime-version