将 Azure 函数作为 C# Web 应用程序进行调试
Debugging Azure function as a C# Web Application
我有一个简单的基于触发器的 Azure 函数,它连接到 Azure 事件中心并在事件中心每次收到消息时写出一条消息。
我根据以下内容将其创建为 C# Web 应用程序 post 并尝试在本地调试此功能:-
https://blogs.msdn.microsoft.com/appserviceteam/2017/03/16/publishing-a-net-class-library-as-a-function-app/
这是我的函数代码:-
using Microsoft.Azure.WebJobs.Host;
using System;
using System.Threading.Tasks;
namespace FunctionLibrary
{
public class EventHubProcessorFunction
{
public static void Run(string myEventHubMessage, TraceWriter log)
{
log.Info($"C# Event Hub trigger function processed a Vineet message: {myEventHubMessage}");
}
}
}
这是我的 function.json
{
"disabled": false,
"scriptFile": ".\bin\FunctionAsWebApp.dll",
"entryPoint": "FunctionLibrary.EventHubProcessorFunction.Run",
"bindings": [
{
"type": "eventHubTrigger",
"name": "myEventHubMessage",
"direction": "in",
"path": "edpvineethub",
"connection": "AzureWebJobsServiceBus"
}
]
}
我的文件夹结构如下:-我在 web 应用程序项目中包含了以下文件:-
bin\FunctionAsWebApp.dll
NameOfYourFunction\function.json
AnotherFunctionIfYouHaveOne\function.json
appsettings.json
host.json
但是,当我尝试在本地 运行 时收到以下错误消息;-
No job functions found. Try making your job classes and methods public. If you'r
e using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've call
ed the registration method for the extension(s) in your startup code (e.g. confi
g.UseServiceBus(), config.UseTimers(), etc.).
如有任何帮助,我们将不胜感激。
检查您的文件夹结构是否如下所示:
bin\FunctionAsWebApp.dll
NameOfYourFunction\function.json
AnotherFunctionIfYouHaveOne\function.json
appsettings.json
host.json
并且function.json
当然应该相应地引用二进制文件
"scriptFile": "..\bin\FunctionAsWebApp.dll"
您的初始化可能无法对 SB 连接字符串执行查找,因为它需要一个 App Setting/Environment 变量名称,而您在那里有实际的连接字符串。
请更新您的 function.json
以使用在本地 appsettings.json
中定义的应用程序设置名称和托管时的功能应用程序设置,并将连接字符串设置为其值。
重要提示:由于上面粘贴了连接字符串,我强烈建议您重置凭据。
我有一个简单的基于触发器的 Azure 函数,它连接到 Azure 事件中心并在事件中心每次收到消息时写出一条消息。
我根据以下内容将其创建为 C# Web 应用程序 post 并尝试在本地调试此功能:- https://blogs.msdn.microsoft.com/appserviceteam/2017/03/16/publishing-a-net-class-library-as-a-function-app/
这是我的函数代码:-
using Microsoft.Azure.WebJobs.Host;
using System;
using System.Threading.Tasks;
namespace FunctionLibrary
{
public class EventHubProcessorFunction
{
public static void Run(string myEventHubMessage, TraceWriter log)
{
log.Info($"C# Event Hub trigger function processed a Vineet message: {myEventHubMessage}");
}
}
}
这是我的 function.json
{
"disabled": false,
"scriptFile": ".\bin\FunctionAsWebApp.dll",
"entryPoint": "FunctionLibrary.EventHubProcessorFunction.Run",
"bindings": [
{
"type": "eventHubTrigger",
"name": "myEventHubMessage",
"direction": "in",
"path": "edpvineethub",
"connection": "AzureWebJobsServiceBus"
}
]
}
我的文件夹结构如下:-我在 web 应用程序项目中包含了以下文件:-
bin\FunctionAsWebApp.dll
NameOfYourFunction\function.json
AnotherFunctionIfYouHaveOne\function.json
appsettings.json
host.json
但是,当我尝试在本地 运行 时收到以下错误消息;-
No job functions found. Try making your job classes and methods public. If you'r
e using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've call
ed the registration method for the extension(s) in your startup code (e.g. confi
g.UseServiceBus(), config.UseTimers(), etc.).
如有任何帮助,我们将不胜感激。
检查您的文件夹结构是否如下所示:
bin\FunctionAsWebApp.dll
NameOfYourFunction\function.json
AnotherFunctionIfYouHaveOne\function.json
appsettings.json
host.json
并且function.json
当然应该相应地引用二进制文件
"scriptFile": "..\bin\FunctionAsWebApp.dll"
您的初始化可能无法对 SB 连接字符串执行查找,因为它需要一个 App Setting/Environment 变量名称,而您在那里有实际的连接字符串。
请更新您的 function.json
以使用在本地 appsettings.json
中定义的应用程序设置名称和托管时的功能应用程序设置,并将连接字符串设置为其值。
重要提示:由于上面粘贴了连接字符串,我强烈建议您重置凭据。