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

标签 azure azure-functions

我创建了一个连接到交换服务器并由 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/

相关文章:

azure - 适用于 Azure 功能的 Winnovative html 到 pdf 转换器

azure - 如何使用 Terraform 将 VM 添加到 Azure 内的负载均衡器中?

c# - 多个包与指定模式匹配 : %s. 请限制搜索模式

.net - 使用 Visual Studio 2017 的 Azure Function 项目的 NuGet 包还原失败

azure - 是否可以使用 Azure Identity 生成多受众声明 JWT token ?

python - 事件中心发送失败 MessageSendResult.Timeout Python

c# - 为什么我的 Azure Functions 在消费计划上运行时无法扩展?

azure - 在 Shell 中使用 URI 将大文件从其他源复制到 Azure Blob

c# - Azure Function,返回状态码+JSON,无需在每个逻辑部分定义返回

Azure Python 函数服务总线出站属性