2

I have this function


    public class Functions
    {
        public Functions()
        {

        }

        [FunctionName("httptriggertest")]
        public async Task<IActionResult> HttpTriggerTest([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "httptriggertest")] HttpRequest req,
            ILogger log)
        {
            log.Log(LogLevel.Information, "Received request request");

            return new OkObjectResult("HttpTriggerTest");
        }
    }

And run it by this:

    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebJobs(b =>
                {
                    b.AddAzureStorageCoreServices()
                        .AddAzureStorage()
                        .AddHttp();
                })
                .ConfigureLogging((context, b) =>
                {
                    b.SetMinimumLevel(LogLevel.Debug);
                    b.AddConsole();
                })
                .ConfigureAppConfiguration(b =>
                {
                    b.AddCommandLine(args);
                })
                .UseConsoleLifetime();
    }

when i run dotnet run it starts fine (the function is discovered by the runtime)

info: Microsoft.Azure.WebJobs.Hosting.JobHostService[0]
      Starting JobHost
info: Host.Startup[0]
      Found the following functions:
      Functions.Functions.HttpTriggerTest

info: Host.Startup[0]
      Job host started
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /home/mslot/git/sut_test/job1
dbug: Microsoft.Extensions.Hosting.Internal.Host[2]
      Hosting started
^Cinfo: Microsoft.Hosting.Lifetime[0]
      Application is shutting down...
dbug: Microsoft.Extensions.Hosting.Internal.Host[3]
      Hosting stopping
info: Microsoft.Azure.WebJobs.Hosting.JobHostService[0]
      Stopping JobHost
info: Host.Startup[0]
      Stopping the listener 'Microsoft.Azure.WebJobs.Extensions.Http.HttpTriggerAttributeBindingProvider+HttpTriggerBinding+NullListener' for function 'httptriggertest'
info: Host.Startup[0]
      Stopped the listener 'Microsoft.Azure.WebJobs.Extensions.Http.HttpTriggerAttributeBindingProvider+HttpTriggerBinding+NullListener' for function 'httptriggertest'
info: Host.Startup[0]
      Job host stopped
dbug: Microsoft.Extensions.Hosting.Internal.Host[4]
      Hosting stopped

But what is the URL for this? Is this even possible on localhost to call the http endpoint? I have tried all sorts of variations of http://localhost/

mslot
  • 4,686
  • 9
  • 39
  • 68

1 Answers1

0

You can get the URL from HttpTrigger route():

route():

  • route() defines the route template, controlling which request URLs your function will respond to. The default value if no route is provided is the function name specified in the FunctionName annotation, applied to each Azure Function.

  • By default when you create a function for an HTTP trigger, or WebHook, the function is addressable with a route of the form http://<yourapp>.azurewebsites.net/api/<funcname>. You can customize this route using this route property. For example, a route of "products/{category:alpha}/{id:int}" would mean that the function is now addressable with the following route instead of the original route: http://<yourapp>.azurewebsites.net/api/products/electronics/357, which allows the function code to support two parameters in the address: category and id.

For example:

[FunctionName("GetCounter")]
public static async Task<HttpResponseMessage> GetCounter(
    [HttpTrigger(AuthorizationLevel.Function, "get", Route = "Counter/{entityKey}")] HttpRequestMessage req,
    [DurableClient] IDurableEntityClient client,
    string entityKey)
{
    var entityId = new EntityId("Counter", entityKey);
    var state = await client.ReadEntityStateAsync<Counter>(entityId); 
    return req.CreateResponse(state);
}

You can refer to open GitHub issue at HTTP Trigger Binding Extensibility and durable entities in .NET

DeepDave-MT
  • 1,861
  • 1
  • 5
  • 18
  • 2
    But what about localhost? My route is a simple "api" but i can't call the http trigger on http(s)://localhost/api/httptriggertest – mslot Aug 25 '21 at 08:12
  • You can report it to Microsoft via [raise support ticket](https://azure.microsoft.com/en-in/support/create-ticket/), [Twitter @AzureSupport](https://twitter.com/AzureSupport) and also ask the same question on [Microsoft Q&A](https://docs.microsoft.com/en-us/answers/products/) – DeepDave-MT Aug 25 '21 at 08:14
  • @mslot you can refer to this: https://stackoverflow.com/a/68079966/15969115 – DeepDave-MT Aug 25 '21 at 08:23
  • 2
    All of this is for azure functions. I am writing a webjob. A simple webjob. I am beginning to think that this isn't possible because i can't find any documentation on how to do it. Is the port 8085 for webjobs as well as azure functions? – mslot Aug 25 '21 at 09:23
  • "...the only way an application can be accessed via the internet is through the already-exposed HTTP (80) and HTTPS (443) TCP ports; applications may not listen on other ports for packets arriving from the internet. However, applications may create a socket which can listen for connections from within the sandbox. For example, two processes within the same app may communicate with one another via TCP sockets; connection attempts incoming from outside the sandbox, albeit they be on the same machine, will fail." – DeepDave-MT Aug 25 '21 at 09:39
  • Reference: [Does the Azure web jobs listen UDP ports?](https://social.msdn.microsoft.com/Forums/azure/en-US/e43b1a4a-ef80-4dca-b9aa-9bc62a2dc781/qampa-redirect-does-the-azure-web-jobs-listen-udp-ports?forum=azureappconfiguration) and [Open additional ports on Azure Web App](https://stackoverflow.com/questions/43516071/open-additional-ports-on-azure-web-app) – DeepDave-MT Aug 25 '21 at 09:40