On several occasions I have spoken of the WebJobs associated with Microsoft Azure Websites, and how we can convert a console application using this service or even launch WebJobs actions using queues or blobs. This time I wanted to show how it is possible run a WebJob from Fiddler or even from our own application.
Download the publish profile
To call a WebJob you must be authenticated but what credentials? With the publish profile. When you use Web Deploy, and you have associated Visual Studio to a Microsoft Azure account, this is a transparent step for us: the IDE download an XML file, which completes the deployment information:
To download the file simply select the website where it hosts the WebJob and click on the Download the publish profile link in the quick glance section:
This file contains the credentials of deployment and publishing (Web Deploy and FTP). For this post, you need to copy the values for: userName (without the site name) and the hash of the password stored in userPWD.
The next step is to know where we have to call to run the WebJob. It is not sufficiently visible on the portal, but there is a URL for each WebJob we created. The pattern is https://SITE_NAME.scm.azurewebsites.net/api/triggeredwebjobs/WEBJOB_NAME/run. Only when we create a scheduled one we can access this information by clicking on the Schedule link WebJob:
This will lead to service Scheduler where you can see all those WebJobs that are being released on a scheduled basis:
If you click on a WebJob, you can see a section called job action, where you can check its setup:
The Scheduler service is performing a POST call to the URL mentioned above with the Authorization header with the credentials are included in publish profile, and a Content-Type using text/plain.
Call from Fiddler
Ready! Now We know how call to WebJobs!. In this example I have used Fiddler to perform the test:
The result of this action should be a 202 (Accepted). Furthermore, you can check the WebJob logs at the following URL: https://SITE_NAME.scm.azurewebsites.net/azurejobs/#/jobs/triggered/WEBJOB_NAME
Hope this helps.
Cheers!