This topic shows you how to perform operations by using SDK for C# to call the required API operations with efficiency. For example, you can create and delete services and functions, and invoke functions.


Before you begin, make sure that you have completed the following operations:

Sample code of SDK for C#

The following code provides an example on how to create and delete services, functions, and triggers:

using System;
using Aliyun.FunctionCompute.SDK.Client;
using Aliyun.FunctionCompute.SDK.Request;
using Aliyun.FunctionCompute.SDK.model;
using System.IO;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text;

namespace samples
    class Program

        static void Main(string[] args)
            var fcClient = new FCClient("cn-shanghai", "<your account id>", "<your ak id>", "<your ak secret>");

            // Create a service.
            var response1 = fcClient.CreateService(new CreateServiceRequest("csharp-service", "create by c# sdk") );
            Console.WriteLine(response1.Data.ServiceName + "---" + response1.Data.Description);

            // Create a function.
            byte[] contents = File.ReadAllBytes(@"/Users/songluo/gitpro/fc-dotnet-sdk/Libraries/samples/");
            var code = new Code(Convert.ToBase64String(contents));
            var response2 = fcClient.CreateFunction(new CreateFunctionRequest("csharp-service", "csharp-function", "python3", "index.handler", code));

            // Asynchronously invoke the function.
            byte[] payload = Encoding.UTF8.GetBytes("hello csharp world");
            var response3 = fcClient.InvokeFunction(new InvokeFunctionRequest("csharp-service", "csharp-function", null, payload));

            var customHeaders = new Dictionary<string, string> {
                {"x-fc-invocation-type", "Async"}

            // Invoke the function.
            var response4 = fcClient.InvokeFunction(new InvokeFunctionRequest("csharp-service", "csharp-function", null, payload, customHeaders));

            // Create a trigger.
            var response5 = fcClient.CreateTrigger(new CreateTriggerRequest("csharp-service", "csharp-function", "my-http-trigger", "http", "dummy_arn", "",
                                                        new HttpTriggerConfig(HttpAuthType.ANONYMOUS, new HttpMethod[] { HttpMethod.GET, HttpMethod.POST })));

            // Delete the trigger.
            var response6 = fcClient.DeleteTrigger(new DeleteTriggerRequest("csharp-service", "csharp-function", "my-http-trigger"));

            // Delete the function.
            var response7 = fcClient.DeleteFunction(new DeleteFunctionRequest("test", "fff2"));

            // Delete the service.
            var response8 = fcClient.DeleteService(new DeleteServiceRequest("csharp"));