为什么 .Net Core / Azure Web 作业示例不起作用?
Why doesn't the .Net Core / Azure Web Job example work?
我正在尝试创建一个 运行 手动触发的 Web 作业(使用 .Net Core 2.1 和 Azure SDK 3.x)。我只是 copying/pasting 示例(手动触发器)中的代码,只是为了获得一个工作起点。但是,当我 运行 示例(本地以及我在 Azure 中的测试服务器上)时,我收到此错误:
'CreateQueueMessage' can't be invoked from Azure WebJobs SDK. Is it
missing Azure WebJobs SDK attributes?'
我已经按照文档中的描述创建了 azure web 作业(.Net Core 控制台应用程序),并且我正在逐字使用示例中的手动触发器(和主机)代码。这是一个错误,还是我需要做其他事情?
文档如下:
https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#triggers
这是我在项目中使用的代码:
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace PubSubTrigger
{
class Program
{
[NoAutomaticTrigger]
public static void CreateQueueMessage(ILogger logger, string value, Queue("outputqueue")] out string message)
{
message = value;
logger.LogInformation("Creating queue message: ", message);
}
static async Task Main(string[] args)
{
var builder = new HostBuilder();
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddAzureStorage();
});
var host = builder.Build();
using (host)
{
var jobHost = host.Services.GetService(typeof(IJobHost)) as JobHost;
var inputs = new Dictionary<string, object>
{
{ "value", "Hello world!" }
};
await host.StartAsync();
await jobHost.CallAsync("CreateQueueMessage", inputs);
await host.StopAsync();
}
}
}
}
作为附加说明,我确实发现了一个类似的问题 posted on SO:
但是,更改目标框架(到 .netstandard)不在 Microsoft 文档的任何部分。而且我觉得很奇怪,文档会指示我专门创建一个 .net 控制台 azure web 作业应用程序,只是稍后将其更改为 .netstandard。而且,只是为了好玩,我确实尝试了该解决方案,但它产生了一个完全不同的错误:
The target process exited without raising a CoreCLR started event.
Ensure that the target process is configured to use .NET Core. This
may be expected if the target process did not run on .NET Core.
所以我认为另一个 post 是一个不同的问题。
只需将class Program
更改为public class Program
即可。
整个代码如下所示:
public class Program
{
[NoAutomaticTrigger]
public static void CreateQueueMessage(ILogger logger, string value, [Queue("myqueue")] out string message)
{
...
}
public static void Main(string[] args)
{
...
...
}
}
我正在尝试创建一个 运行 手动触发的 Web 作业(使用 .Net Core 2.1 和 Azure SDK 3.x)。我只是 copying/pasting 示例(手动触发器)中的代码,只是为了获得一个工作起点。但是,当我 运行 示例(本地以及我在 Azure 中的测试服务器上)时,我收到此错误:
'CreateQueueMessage' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes?'
我已经按照文档中的描述创建了 azure web 作业(.Net Core 控制台应用程序),并且我正在逐字使用示例中的手动触发器(和主机)代码。这是一个错误,还是我需要做其他事情?
文档如下: https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#triggers
这是我在项目中使用的代码:
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace PubSubTrigger
{
class Program
{
[NoAutomaticTrigger]
public static void CreateQueueMessage(ILogger logger, string value, Queue("outputqueue")] out string message)
{
message = value;
logger.LogInformation("Creating queue message: ", message);
}
static async Task Main(string[] args)
{
var builder = new HostBuilder();
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddAzureStorage();
});
var host = builder.Build();
using (host)
{
var jobHost = host.Services.GetService(typeof(IJobHost)) as JobHost;
var inputs = new Dictionary<string, object>
{
{ "value", "Hello world!" }
};
await host.StartAsync();
await jobHost.CallAsync("CreateQueueMessage", inputs);
await host.StopAsync();
}
}
}
}
作为附加说明,我确实发现了一个类似的问题 posted on SO:
但是,更改目标框架(到 .netstandard)不在 Microsoft 文档的任何部分。而且我觉得很奇怪,文档会指示我专门创建一个 .net 控制台 azure web 作业应用程序,只是稍后将其更改为 .netstandard。而且,只是为了好玩,我确实尝试了该解决方案,但它产生了一个完全不同的错误:
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
所以我认为另一个 post 是一个不同的问题。
只需将class Program
更改为public class Program
即可。
整个代码如下所示:
public class Program
{
[NoAutomaticTrigger]
public static void CreateQueueMessage(ILogger logger, string value, [Queue("myqueue")] out string message)
{
...
}
public static void Main(string[] args)
{
...
...
}
}