Azure Function 在 Visual Studio 中运行良好,但发布后不会被触发 [英] Azure Function works fine in visual studio but is not being triggered once published

查看:14
本文介绍了Azure Function 在 Visual Studio 中运行良好,但发布后不会被触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个连接到交换服务器并由 blob 存储触发器触发的天蓝色函数.在visual studio中测试,一切正常;上传 blob 会触发函数并尝试连接.

I have Created an azure function that connects to an exchange server and is triggered by a blob storage trigger. Testing this in visual studio, everything works fine; uploading a blob triggers the function and the connection is attempted.

但是,当我将函数发布到 Azure 时,上传文件时它不再由 blob 存储触发.

When I publish the function to Azure however, it is no longer triggered by the blob storage when a file is uploaded.

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

The application and the function are both visible on the azure portal and the application is running. But the invocation log states that the function is never called. The function is also listed as read-only due to being developed in Visual Studio.

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

Is there a step I am missing after testing my function in visual studio and publishing the application to Azure?

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

Absolutely any help would be appreciated, I’m sure I am just doing something incredibly stupid.

谢谢.

其他信息:我从 Visual Studio 2017 Enterprise 发布

Additional Information: I'm publishing from 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
 Name:{name} 
 Size:  Bytes");
            log.Info(myBlob.ToString());
            ExchangeService service = new ExchangeService();
            String customer = myBlob.DownloadText();


            string emailAddress = "email@email-test.local";

            //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:Usersdavelsource
eposExchangeSimplifiedTestFunctionExchangeSimplifiedTestFunctioninDebug
et461host.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 功能.

Just like Mikhail' comment, you should add the storage connection string into your Azure function's application settings. The file local.settings.json only works in your local develop environment, which does not work in azure function.

这篇关于Azure Function 在 Visual Studio 中运行良好,但发布后不会被触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆