The SDK of this version is dependent on the third-party library Json.NET. This componenent is for Aliyun FunctionCompute developers to build C# functions.
Applicable to .net core 2.1 or above
-
If NuGet hasn't been installed for Visual Studio, install NuGet first.
-
After NuGet is installed, access Visual Studio to create a project or open an existing project, and then select
TOOLS
>NuGet Package Manager
>Manage NuGet Packages for Solution
. -
For normal invoke function, type
Aliyun.Serverless.Core
in the search box and click Search, select the latest version, and click Install. -
For http invoke function, beside
Aliyun.Serverless.Core
, you also need to installAliyun.Serverless.Core.Http
.
using System;
using System.IO;
using System.Threading.Tasks;
using Aliyun.Serverless.Core;
using Microsoft.Extensions.Logging;
namespace samples
{
public class TestHandler
{
public async Task<Stream> EchoEvent(Stream input, IFcContext context)
{
context.Logger.LogInformation("Handle Request: {0}", context.RequestId);
MemoryStream memoryStream = new MemoryStream();
await input.CopyToAsync(memoryStream);
return memoryStream;
}
}
}