从代码运行触发的Azure WebJob [英] Run triggered Azure WebJob from Code

查看:87
本文介绍了从代码运行触发的Azure WebJob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个作为Azure触发器Webjob上传的控制台应用程序.当我从Azure Portal运行它时,它运行良好.我想从我的C#代码中运行它.我不想使用队列或服务总线.我只想在用户在我的Web应用程序中执行特定操作时触发它.

I created a console application upload as Azure trigger Webjob. It is working fine when I run it from Azure Portal. I want to run this from my C# code. I don't want to use Queue or service bus. I just want to trigger it when user perform a specific action in my web app.

搜索后,我得到了一个解决方案,可以按计划触发作业 http://blog.davidebbo.com/2015/05/scheduled-webjob.html

After searching I got a solution to trigger job from a scheduled http://blog.davidebbo.com/2015/05/scheduled-webjob.html

有人知道如何从代码运行吗?

Any idea how to run from code?

推荐答案

正如Justin所说,我们可以使用WebJob API来达到此要求.我们可以在以下位置找到此KUDU API: https://github.com/projectkudu/kudu/wiki/WebJobs-API .下面是我经过测试的代码:

As Justin said, we can use WebJob API to achieve this requirement. We could find this KUDU API at: https://github.com/projectkudu/kudu/wiki/WebJobs-API. Below is my tested code:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://<web appname>.scm.azurewebsites.net/api/triggeredwebjobs/<web job name>/run");
request.Method = "POST";
var byteArray = Encoding.ASCII.GetBytes("user:password"); //we could find user name and password in Azure web app publish profile 
request.Headers.Add("Authorization", "Basic "+ Convert.ToBase64String(byteArray));            
request.ContentLength = 0;
try
{
    var response = (HttpWebResponse)request.GetResponse();
}
catch (Exception e) {

}

它对我有效.希望对您有所帮助.

It works on my side. Hope it helps.

这篇关于从代码运行触发的Azure WebJob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆