0

I'm looking to create a WebJob that takes in a request and sends a response, much like an Azure Function with an HTTP trigger. I want to use a WebJob instead because I need to use wkhtmltopdf, which cannot run on a Consumption plan, and we are already paying for an App Service that it can run on.

I know how to run the WebJob using an HTTP POST from this link: https://stackoverflow.com/a/42824776/443044.

What I cannot figure out is how to create the WebJob itself.

Here is my Program class:

public class Program
{

    [NoAutomaticTrigger]
    public static void TestMethod(TextWriter logger)
    {
        logger.WriteLine("TEST: " + req.Content.ToString());
    }

    // Please set the following connection strings in app.config for this WebJob to run:
    // AzureWebJobsDashboard and AzureWebJobsStorage
    static void Main()
    {
        var config = new JobHostConfiguration();

        ...

        var host = new JobHost(config);
        host.Call(typeof(Program).GetMethod("TestMethod"), null);
    }
}

The program throws an exception if I try to give TestMethod the return type of HttpResponseMessage or a parameter of type HttpRequestMessage.

How can I achieve the request/response functionality like with an Azure Function?

Anonymous1
  • 3,877
  • 3
  • 28
  • 42
  • I did not realize that. I'll see if I can call wkhtmltopdf from an Azure Function on that app plan. – Anonymous1 Jul 02 '18 at 06:00
  • I got it working with an Azure Function on the existing app plan. Thanks! – Anonymous1 Jul 02 '18 at 07:28
  • @PeterBons you should add this as an Answer instead of a comment. – David Ebbo Jul 02 '18 at 19:30
  • @DavidEbbo yeah you're right, fixed it :-) – Peter Bons Jul 02 '18 at 19:32
  • @Anonymous1 I'm looking for a similar solution that uses an azure function to convert html to pdf using wkhtmltopdf. Can you provide a link or shoot an example of how you got the native libraries working P/Invoking or however you did it in an azure function? I'm stumped. – EdFred Jan 24 '20 at 16:05
  • @EdFred I found this helpful for the PDF conversion: https://stackoverflow.com/a/6787041/443044. You need to first create a stream of the HTML code: https://stackoverflow.com/a/1879470/443044. – Anonymous1 Jan 27 '20 at 06:59

1 Answers1

3

we are already paying for an App Service -> You do realize you can host your azure function on an existing app plan as well? learn.microsoft.com/en-us/azure/azure-functions/….

But AFAIK webjobs do not have capabilities to respond to requests.

Peter Bons
  • 26,826
  • 4
  • 50
  • 74