gpt4 book ai didi

Azure Function 在 Visual Studio 中运行良好,但发布后不会被触发

转载 作者:行者123 更新时间:2023-12-01 03:19:02 25 4
gpt4 key购买 nike

我创建了一个连接到交换服务器并由 blob 存储触发器触发的 azure 函数。在 Visual Studio 中进行测试,一切正常;上传 blob 会触发该函数并尝试连接。

但是,当我将该函数发布到 Azure 时,上传文件时 Blob 存储不再触发该函数。

应用程序和函数在 Azure 门户上均可见,并且应用程序正在运行。但调用日志表明该函数从未被调用。由于该函数是在 Visual Studio 中开发的,因此该函数也被列为只读。

在 Visual Studio 中测试我的功能并将应用程序发布到 Azure 后,我是否缺少一个步骤?

任何帮助都将不胜感激,我确信我只是在做一些极其愚蠢的事情。

谢谢。

其他信息:我从 Visual studio 2017 Enterprise 进行发布

这是函数

using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Exchange.WebServices.Data;
using System;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Security;
using System.Net;

namespace ExchangeSimplifiedTestFunction
{
public static class SimplifiedFunction
{
[FunctionName("SimplifiedFunction")]
public static void Run([BlobTrigger("exchangestorage/{name}", Connection = "StorageConnection")]CloudBlockBlob myBlob, string name, TraceWriter log)
{

log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: Bytes");
log.Info(myBlob.ToString());
ExchangeService service = new ExchangeService();
String customer = myBlob.DownloadText();


string emailAddress = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3b6beb2babf93b6beb2babffea7b6a0a7fdbfbcb0b2bf" rel="noreferrer noopener nofollow">[email protected]</a>";

//yuck yuck yuck yuck yuck
var password = new SecureString(); foreach (char c in "password") password.AppendChar(c);

NetworkCredential userCredentials = new NetworkCredential(emailAddress, password);
service.Credentials = userCredentials;

bool success;
try
{
service.AutodiscoverUrl(emailAddress, RedirectionUrlValidationCallback);
success = true;
}
catch (Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException e)
{
log.Info($"loginFailed - expected during testing");
success = false;
}

if (success) { log.Info($"Successfully connected to exchange server"); }

}

private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
bool result = false;
Uri redirectionUri = new Uri(redirectionUrl);

if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}

}
}

这是 local.settings.json

{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=exchangclientestorage;AccountKey=[accountKey];EndpointSuffix=core.windows.net",
"AzureWebJobsDashboard": "",
"StorageConnection": "DefaultEndpointsProtocol=https;AccountName=exchangclientestorage;AccountKey=[accountKey];EndpointSuffix=core.windows.net"

}
}

这是本地测试的结果

                %%%%%%
@ %%%%%% @
@@ %%%%%% @@
@@@ %%%%%%%%%%% @@@
@@ %%%%%%%%%% @@
@@ %%%% @@
@@ %%% @@
@@ %% @@
%%
%

[14/11/2017 11:46:05] Reading host configuration file 'C:\Users\davel\source\repos\ExchangeSimplifiedTestFunction\ExchangeSimplifiedTestFunction\bin\Debug\net461\host.json'
[14/11/2017 11:46:05] Host configuration file read:
[14/11/2017 11:46:05] {
}
Listening on http://localhost:7071/
Hit CTRL-C to exit...
[14/11/2017 11:46:05] Generating 1 job function(s)
[14/11/2017 11:46:05] Starting Host (HostId=dlopcdi101-792492740, Version=1.0.11075.0, ProcessId=14848, Debug=False, Attempt=0)
[14/11/2017 11:46:06] Found the following functions:
[14/11/2017 11:46:06] ExchangeSimplifiedTestFunction.SimplifiedFunction.Run
[14/11/2017 11:46:06]
[14/11/2017 11:46:06] Host lock lease acquired by instance ID '000000000000000000000000860DF48B'.
[14/11/2017 11:46:06] Job host started
[14/11/2017 11:46:06] Executing HTTP request: {
[14/11/2017 11:46:06] "requestId": "ae39ae2c-8e64-4b22-bbd9-26215f558b4a",
[14/11/2017 11:46:06] "method": "GET",
[14/11/2017 11:46:06] "uri": "/"
[14/11/2017 11:46:06] }
[14/11/2017 11:46:06] Executed HTTP request: {
[14/11/2017 11:46:06] "requestId": "ae39ae2c-8e64-4b22-bbd9-26215f558b4a",
[14/11/2017 11:46:06] "method": "GET",
[14/11/2017 11:46:06] "uri": "/",
[14/11/2017 11:46:06] "authorizationLevel": "Anonymous"
[14/11/2017 11:46:06] }
[14/11/2017 11:46:06] Response details: {
[14/11/2017 11:46:06] "requestId": "ae39ae2c-8e64-4b22-bbd9-26215f558b4a",
[14/11/2017 11:46:06] "status": "OK"
[14/11/2017 11:46:06] }
[14/11/2017 11:46:06] Function started (Id=85129700-5403-42b3-9368-3f185503e73a)
[14/11/2017 11:46:06] Executing 'SimplifiedFunction' (Reason='New blob detected: exchangestorage/customer3.txt', Id=85129700-5403-42b3-9368-3f185503e73a)
[14/11/2017 11:46:07] C# Blob trigger function Processed blob
Name:customer3.txt
Size: Bytes
[14/11/2017 11:46:07] Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob
Debugger listening on [::]:5858
[14/11/2017 11:46:09] loginFailed - expected during testing
[14/11/2017 11:46:09] Function completed (Success, Id=85129700-5403-42b3-9368-3f185503e73a, Duration=3135ms)
[14/11/2017 11:46:09] Executed 'SimplifiedFunction' (Succeeded, Id=85129700-5403-42b3-9368-3f185503e73a)

最后生成的 function.json

{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
"configurationSource": "attributes",
"bindings": [
{
"type": "blobTrigger",
"connection": "StorageConnection",
"path": "exchangestorage/{name}",
"name": "myBlob"
}
],
"disabled": false,
"scriptFile": "..\\bin\\ExchangeSimplifiedTestFunction.dll",
"entryPoint": "ExchangeSimplifiedTestFunction.SimplifiedFunction.Run"
}

最佳答案

就像 Mikhail 的评论一样,您应该将存储连接字符串添加到 Azure 函数的应用程序设置中。 local.settings.json 文件仅适用于本地开发环境,不适用于 azure 函数。 enter image description here

关于Azure Function 在 Visual Studio 中运行良好,但发布后不会被触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47286303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com