This topic describes how to install SDKs for .NET and provides sample code.

Background information

  • To use Resource Management SDK for .NET, you must install both the core library of Alibaba Cloud SDK for .NET(aliyun-net-sdk-core) and Resource Management SDK for .NET (alibabacloud-csharp-sdk).
  • Alibaba Cloud provides OpenAPI Developer Portal to simplify API usage. You can use OpenAPI Explorer to debug API operations and dynamically generate SDK sample code.
  • For more information about Resource Management API operations, see List of operations by function.

Installation

For more information about how to install the SDKs for .NET, see Get started.

You can download the installation packages of the SDKs for .NET from the following links:

Example

The following code provides an example on how to use Resource Management SDK for .NET to call the CreateResourceAccount operation. You can use OpenAPI Developer Portal to debug other API operations and obtain their sample code.

using System;
using System.Collections.Generic;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Http;

namespace CommonRequestDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // Construct an Alibaba Cloud client that is used to initiate requests.
            // When you construct the client, specify your AccessKey ID and AccessKey secret.
            IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "<accessKeyId>", "<accessKeySecret>");
            DefaultAcsClient client = new DefaultAcsClient(profile);
            // Construct a request and specify request parameters. For more information about the parameters, see API Reference.
            CommonRequest request = new CommonRequest();
            request.Method = MethodType.POST;
            request.Domain = "resourcemanager.aliyuncs.com";
            request.Version = "2020-03-31";
            request.Action = "CreateResourceAccount";
            // request.Protocol = ProtocolType.HTTP;
            request.AddQueryParameters("DisplayName", "<DisplayName>");

            // Initiate the request and obtain a response.
            try {
                CommonResponse response = client.GetCommonResponse(request);
                Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
            }
            catch (ServerException e)
            {
                Console.WriteLine(e);
            }
            catch (ClientException e)
            {
                Console.WriteLine(e);
            }
        }
    }
}