2

I am able to call azure functions from ADF and postman but when I call durable functions from ADF or postman it gives me error:

Operation on target Azure Function1 failed: Call to provided Azure function '' failed with status-'NotFound' and message - 'Invoking Azure function failed with HttpStatusCode - NotFound.'.

I have tried everything but dont know why this is happening. I have created durable function through portal in functionApp as follow:

DurableFunctionsHttpStart1:

#r "Microsoft.Azure.WebJobs.Extensions.DurableTask"
#r "Newtonsoft.Json"

using System.Net;

public static async Task<HttpResponseMessage> Run(
    HttpRequestMessage req,
    DurableOrchestrationClient starter,
    ILogger log)
{
    // Function input comes from the request content.
    dynamic eventData = await req.Content.ReadAsAsync<object>();

    // Pass the function name as part of the route 
    string instanceId = await starter.StartNewAsync("DurableFunctionsOrchestrator1", null);

    log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

    return starter.CreateCheckStatusResponse(req, instanceId);
}

DurableFunctionsOrchestrator1:

/*
 * This function is not intended to be invoked directly. Instead it will be
 * triggered by an HTTP starter function.
 * 
 * Before running this sample, please:
 * - create a Durable activity function (default name is "Hello")
 * - create a Durable HTTP starter function
 */

#r "Microsoft.Azure.WebJobs.Extensions.DurableTask"

public static async Task<List<string>> Run(DurableOrchestrationContext context)
{
    var outputs = new List<string>();

    // Replace "Hello" with the name of your Durable Activity Function.
    outputs.Add(await context.CallActivityAsync<string>("Hello1", "Tokyo"));
    outputs.Add(await context.CallActivityAsync<string>("Hello1", "Seattle"));
    outputs.Add(await context.CallActivityAsync<string>("Hello1", "London"));

    // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
    return outputs;
}

Hello1:

/*
 * This function is not intended to be invoked directly. Instead it will be
 * triggered by an orchestrator function.
 * 
 * Before running this sample, please:
 * - create a Durable orchestration function
 * - create a Durable HTTP starter function
 */

#r "Microsoft.Azure.WebJobs.Extensions.DurableTask"

using System;
using System.Threading;

public static string Run(string name)
{
    Thread.Sleep(260000);
    return $"Hello {name}!";
}

From ADF side I am calling DurableFunctionsHttpStart1 function, which will call orchestrator function and activity will be called. Please guide

Bilal Shafqat
  • 689
  • 2
  • 14
  • 26
  • Also face this problem when use postman to call the httpstart? – Cindy Pau Feb 27 '20 at 10:13
  • 1
    @BowmanZhu. An update, So in postman I was using wrong url so that why i was getting 404 - function NotFound. URL seems to be https://.azurewebsites.net/api/orchestrators/DurableFunctionsOrchestrator1 but I was trying with https://.azurewebsites.net/api/DurableFunctionsOrchestrator1. So I was missing orchestrator in it. But how i will call it in ADF? I have created a linked service with function app and function key but getting 404 - NotFound. Please guide. – Bilal Shafqat Feb 27 '20 at 10:25

1 Answers1

1

Update: Reproduce your error on ADF, this is what you are facing now:

enter image description here

If your function in ADF is like this, you will get the above error. enter image description here (Also the method need to be post)

This is the configuration of the azure function in ADF should be:

enter image description here

Then it works fine on my ADF.

Original Answer:

These code work fine on my side:

DurableFunctionsHttpStart1

#r "Microsoft.Azure.WebJobs.Extensions.DurableTask"
#r "Newtonsoft.Json"

using System.Net;

public static async Task<HttpResponseMessage> Run(
    HttpRequestMessage req,
    DurableOrchestrationClient starter,
    string functionName,
    ILogger log)
{
    // Function input comes from the request content.
    dynamic eventData = await req.Content.ReadAsAsync<object>();

    // Pass the function name as part of the route 
    string instanceId = await starter.StartNewAsync("DurableFunctionsOrchestrator1", eventData);

    log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

    return starter.CreateCheckStatusResponse(req, instanceId);
}

DurableFunctionsOrchestrator1

/*
 * This function is not intended to be invoked directly. Instead it will be
 * triggered by an HTTP starter function.
 * 
 * Before running this sample, please:
 * - create a Durable activity function (default name is "Hello")
 * - create a Durable HTTP starter function
 */

#r "Microsoft.Azure.WebJobs.Extensions.DurableTask"

public static async Task<List<string>> Run(DurableOrchestrationContext context)
{
    var outputs = new List<string>();

    // Replace "Hello" with the name of your Durable Activity Function.
    outputs.Add(await context.CallActivityAsync<string>("Hello1", "Tokyo"));
    outputs.Add(await context.CallActivityAsync<string>("Hello1", "Seattle"));
    outputs.Add(await context.CallActivityAsync<string>("Hello1", "London"));

    // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
    return outputs;
}

Hello1

/*
 * This function is not intended to be invoked directly. Instead it will be
 * triggered by an orchestrator function.
 * 
 * Before running this sample, please:
 * - create a Durable orchestration function
 * - create a Durable HTTP starter function
 */

#r "Microsoft.Azure.WebJobs.Extensions.DurableTask"
using System;
using System.Threading;
public static string Run(string name)
{
    Thread.Sleep(260000);
    return $"Hello {name}!";
}

And all the function triggered well, at last:

enter image description here

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • An update, So in postman I was using wrong url so that why i was getting 404 - function NotFound. URL seems to be https://.azurewebsites.net/api/orchestrators/DurableFunctionsOrchestrator1 but I was trying with https://.azurewebsites.net/api/DurableFunctionsOrchestrator1. So I was missing orchestrator in it. But how i will call it in ADF? I have created a linked service with function app and function key but getting 404 - NotFound. Please guide. – Bilal Shafqat Feb 27 '20 at 10:29
  • 1
    @BilalShafqat I have update my answer. Check if your function name is wrong. And the method should be POST. – Cindy Pau Feb 27 '20 at 11:32
  • 1
    @BilalShafqat Any questions? I'm going to bed,if you have more doubts please leave me a message. – Cindy Pau Feb 27 '20 at 12:09
  • yes I have... I was missing Orchestrator in function name in ADF. – Bilal Shafqat Feb 27 '20 at 12:16
  • But even after mentioning, I am still unable. let me try again and I will reach you in a minute. – Bilal Shafqat Feb 27 '20 at 12:17
  • 1
    Thanks alot @BowmanZhu. I am able to run it through ADF. I was doing 2 mistakes. 1) In the function Name in ADF I was not mentioning "orchestrators". And 2) Instead of function Name "DurableFunctionsHttpStart1" i mentioned function Name "DurableFunctionsOrchestrator1". So here is another thing I want to ask: I think I should be calling "DurableFunctionsHttpStart1" function as it is a HTTP function and then this function should call Orchestrator function but calling HTTP function "DurableFunctionsHttpStart1" gives me function NotFound. Please guide. – Bilal Shafqat Feb 27 '20 at 12:35
  • 1
    @BilalShafqat Hi, Bilal. Thanks for your sharing. The function name in ADF should be the part of the url of your DurableFunctionsHttpStart1. The url is getting from [this place](https://i.stack.imgur.com/4bgvO.png). On my side, the url is [this](https://i.stack.imgur.com/eVx43.png). The function name should be part of the url. On my side, it is orchestrators/{functionName} – Cindy Pau Feb 28 '20 at 00:09