gpt4 book ai didi

asp.net-mvc - 调用的 Webjob 不考虑传递的参数

转载 作者:行者123 更新时间:2023-12-03 05:54:04 26 4
gpt4 key购买 nike

我正在从应用服务环境中托管的 Web 应用程序调用 Web 作业。我用来调用的代码如下:

string userName = "$xxxx";
string userPassword = "xxxxx";
string webJobName = "xxxx";

var unEncodedString = String.Format($"{ userName}:{ userPassword}");
var encodedString = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(unEncodedString));
string URL = string.Format("https://xxxx.scm.azurewebsites.net/api/triggeredwebjobs/" + webJobName + "/run?arguments={0}", jobId.ToString());
System.Net.WebRequest request = System.Net.WebRequest.Create(URL);
request.Method = "POST";
request.ContentLength = 0;
request.Headers["Authorization"] = "Basic " +encodedString;
response = request.GetResponse();

我正在调用一个 Webjob,它是一个控制台应用程序。我如何处理控制台应用程序中的参数如下:

static void Main(string[] args)
{
//
var id = 0;
if (args.Length > 0)
{
if (!int.TryParse(args[0].ToString(), out id))
id = 0;
}


if (id > 0)
{
EmailJobExecution emailServ = new EmailJobExecution();
EmailJobDBContext jobDB = new EmailJobDBContext();

var jobs = jobDB.getActiveJob(id);

List<string> logs = new List<string>();
emailServ.ExecuteJob(jobs, out logs);

foreach (var item in logs)
{
Console.WriteLine(item);
}
}
}

问题是我可以在 Webjob 仪表板中看到 webjob 已被调用,但参数未传递。日志显示为:

[05/30/2017 11:18:51 > 738495: SYS INFO] Status changed to Initializing

[05/30/2017 11:18:51 > 738495: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'

[05/30/2017 11:18:51 > 738495: SYS INFO] Status changed to Running

[05/30/2017 11:18:51 > 738495: INFO]

[05/30/2017 11:18:51 > 738495: INFO] D:\local\Temp\jobs\triggered\xxxxx\rwjgkw42.ann>xxxx.EXE

[05/30/2017 11:18:51 > 738495: SYS INFO] Status changed to Success

如果我进入应用服务编辑器并像这样修改 run.cmd:xxxx.EXE 1(1 是参数),那么控制台将采用如下参数和日志:

[05/30/2017 10:17:26 > 738495: SYS INFO] Status changed to Initializing

[05/30/2017 10:17:27 > 738495: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'

[05/30/2017 10:17:27 > 738495: SYS INFO] Status changed to Running

[05/30/2017 10:17:27 > 738495: INFO]

[05/30/2017 10:17:27 > 738495: INFO] D:\local\Temp\jobs\triggered\xxxx\bvck11x1.f3v>xxx.EXE 1

[05/30/2017 10:17:32 > 738495: INFO] 5/30/2017 10:17:27 AM: Job No. 1 Started

[05/30/2017 10:17:32 > 738495: INFO] Message Count: 1

[05/30/2017 10:17:32 > 738495: INFO] 1:OK

[05/30/2017 10:17:32 > 738495: INFO] Status Count: 1

[05/30/2017 10:17:32 > 738495: INFO] 5/30/2017 10:17:32 AM: Job No. 1 Completed

[05/30/2017 10:17:32 > 738495: SYS INFO] Status changed to Success

即使我在 Postman 中运行 URL,参数也不会通过。

请帮我解决这个问题。

Update 31st May 2017:

The Zip Package for Webjobs had the following:

  1. run.cmd
  2. xxxx.EXE

and as @SuwatCh guided me, I removed the run.cmd and leaving only the *.exe in Zip Package and then created the WebJob and finally it worked!

最佳答案

以这种方式传递参数应该可以正常工作。请使用最小的应用程序进行测试,因为您所做的与 EmailJobExecution 相关的所有操作与问题无关,应省略。另外,如果您也使用 postman 进行重现,您的客户端代码与该问题无关,因此请忽略它。

例如我刚刚尝试使用一个简单的批处理文件,其中仅包含:

echo Hello Azure WebJob!
echo command line arg %1
echo env variable %WEBJOBS_COMMAND_ARGUMENTS%

并且 %1%WEBJOBS_COMMAND_ARGUMENTS% 都正确地具有传入的值。

关于asp.net-mvc - 调用的 Webjob 不考虑传递的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44261144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com