Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Function works fine in visual studio but is not being triggered once published

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.

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

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.

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.

Thanks.

Additional Information: I'm publishing from Visual studio 2017 Enterprise

Here's the Function

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 protected]";

            //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;
        }

    }
}

And Here's the 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"

  }
}

And Here are the results from testing locally

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

[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)

And Finally the generated 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"
}
like image 342
Dave Avatar asked Oct 28 '22 23:10

Dave


1 Answers

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. enter image description here

like image 108
Crazy Crab Avatar answered Nov 11 '22 18:11

Crazy Crab