请求处理程序(Handler) 本文介绍如何使用C 请求处理程序响应接收到的事件并执行相应的业务逻辑。 请求处理程序 请求处理程序是一个执行的入口方法,当您的函数被调用时,函数计算会运行该方法处理请求。 您可以通过函数计算控制台页面配置请求处理程序 ,对于C 语言的函数,请求处理程序需配置为 [程序集名称]::[命名空间].[类名]::[方法名]。例如,您的程序集名称为HelloApp,命名空间为Example,方法名为Hello,方法名为Handler,则请求处理程序可配置为 HelloApp::Example.Hello::Handler。 如下是一个请求处理程序的方法实现示例: csharp using System; using System.IO; using System.Text; using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Serverless.Cf; namespace Example { public class Hello { public async Task Handler(Stream input, ICfContext context) { } static void Main(string[] args) { } } } 请求处理程序支持以下方法签名: csharp // 包含ICfContext的同步方法 OutType Handler(InType input, ICfContext context); // 不包含ICfContext的同步方法 OutType Handler(InType input); // 包含ICfContext的异步方法 Async Task Handler(InType input, ICfContext context); // 不包含ICfContext的异步方法 Async Task Handler(InType input); 方法签名说明: 方法名称:方法名称可自定义。 返回值:void、System.IO.Stream或可以被JSON序列化和反序列化的对象。 方法入参:第一个入参是 System.IO.Stream或可以被JSON序列化和反序列化的对象;第二个入参可选,当存在第二个入参时,必须是 ICfContext类型。 如果您使用到ICfContext接口,需要在代码目录下的csproj文件引入Serverless.Cf依赖: xml