I'm running an Azure webjob alongside an Azure webapp. The job runs periodically and the result of the job is needed in the webapp. How do I get the result there?
I tried with a WCF netNamedPipeBinding
but since there are no startup tasks for Azure webapps I cannot add a net.pipe binding to the IIS website nor can I enable the net.pipe protocol.
I have it working now with a basicHttpBinding
but this binding is exposed to the entire internet which I absolutely do not want. I simply want machine-local communication between a webjob and webapp running on the same machine.
CORRECTION: I thought I had it working on Azure but that is not the case. When running on Azure I get an error from the webjob: An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:80
(using basicHttpBinding
). Probably the webapp has an internal port number I don't know.
You have a few options:
- Use the file system to pass messages
- Use Azure Storage Queues to pass messages between the two
- Use Azure Service Bus Queue to pass messages
- Use any shared storage (database, Azure Storage, etc) to pass messages
The benefit of all these approaches is that it makes your message passing async and thus more resilient to one of the two services (web app or web job) going down for some time.
You can use the file-system to communicate between the WebJob and the Websites.
It is shared between them and between all of your instances.
Simply write a file from the WebJob and use a file system watcher in your webapp to recognize when a file is created or changed.
Note you cannot communicate through localhost in Azure Websites (or WebJobs) and cannot listen on a port that is not 80/443.
You can use azure service bus queue, then point your service (web app) to consume messages from queue.
The closest answer is to set WEBSITE_DISABLE_SCM_SEPARATION=true
in App Settings. This will enable WebApp and SCM processes work in same sandbox. Unfortunately this option is deprecated by Azure and no longer supported. Thanks all for attempting the answer. More information can be found here.