Azure Function在Visual Studio中工作正常,但发布后不会触发 [英] Azure Function works fine in visual studio but is not being triggered once published

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

问题描述

我创建了一个连接到交换服务器并由blob存储触发器触发的azure函数.在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\n Name:{name} \n 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:\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)

最后是生成的函数.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天全站免登陆