.NET SDK user guide

Last Updated: Dec 05, 2017


Welcome to the Alibaba Cloud Software Development Kit (SDK). Alibaba Cloud .NET SDK allows you to access multiple Alibaba Cloud services such as ECS and CloudMonitor without complex coding. We will introduce how to get Alibaba Cloud .NET SDK and use it.

Prepare the environment

  1. Alibaba Cloud .NET SDK is available for .NET Framework 4.0 and later versions.

  2. To use Alibaba Cloud .NET SDK, you need an Alibaba Cloud account and an Access Key ID and Access Key Secret. Create and view your AccessKey in Alibaba Cloud console, or contact the system administrator.

  3. To access a product API with Alibaba Cloud SDK, activate the product in Alibaba Cloud console.

How to get and install SDK

Go to the .NET SDK resource list to download the SDK.

Note: SDKs of some Alibaba Cloud products, for example Object Storage Service (OSS) and Table Store, are not in this list, go to the details page of these products for corresponding SDKs.

To use the SDK of a product, you must install SDK Core Library first. For example, to use ECS SDK, install two SDKs, namely, SDK Core Library and ECS SDK.

You can install Alibaba Cloud .NET SDK with the following methods:

Method 1: Add DLL reference

Download the compressed package containing DLL files from .NET SDK resource list, and extract it to get the DLL files.

Select your items in Solution Explorer in Visual Studio, and right click on Project Name -> References, and select Add Reference, and when the Add Reference dialog is displayed, click Browse to select the downloaded and decompressed DLL files, then click OK.

Method 2: Project introduction

First download .NET SDK source code from GitHub:

  1. git clone https://github.com/aliyun/aliyun-openapi-net-sdk.git

You can find multiple sub-folders named aliyun-net-openapi-XXX in the downloaded folder, a *.csproj file also exists there, which is the C# project file. For example, in the sub-folder aliyun-net-openapi-ecs, there is a file named aliyun-net-sdk-ecs.csproj.

In the Visual Studio interface, right click Solution, and click Add->Existing Projects. Select the corresponding C# project file from the downloaded source code, for example aliyun-net-sdk-ecs.csproj, and click Open.

Then, right click Your Projects -> References, and select Add Reference -> Projects -> the project you just opened, for example aliyun-net-sdk-ecs, and click OK.

Start to use

The following code shows the three main steps to use Alibaba Cloud SDK:

  1. Create a DefaultAcsClient instance and initialize it;
  2. Create an API request and set parameters;
  3. Initiate the request and process the response.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Aliyun.Acs.Core;
  7. using Aliyun.Acs.Core.Profile;
  8. using Aliyun.Acs.Core.Exceptions;
  9. using Aliyun.Acs.Ecs.Model.V20140526;
  10. namespace TestApp
  11. {
  12. class TestProgram
  13. {
  14. static void Main(string[] args)
  15. {
  16. // Construct an Aliyun Client for initiating a request
  17. IClientProfile profile = DefaultProfile.GetProfile(
  18. "<your-region-id>",
  19. "<your-access-key-id>",
  20. "<your-access-key-secret>");
  21. DefaultAcsClient client = new DefaultAcsClient(profile);
  22. // Construct the request
  23. DescribeInstancesRequest request = new DescribeInstancesRequest();
  24. request.PageSize = 10;
  25. // Initiate a request and obtain the response
  26. try
  27. {
  28. DescribeInstancesResponse response = client.GetAcsResponse(request);
  29. System.Console.WriteLine(response.TotalCount);
  30. }
  31. catch (ServerException ex)
  32. {
  33. System.Console.WriteLine(ex.ToString());
  34. }
  35. catch (ClientException ex)
  36. {
  37. System.Console.WriteLine(ex.ToString());
  38. }
  39. }
  40. }
  41. }

When you create a DefaultAcsClient instance and initialize it, three parameters are required: Region ID, Access Key ID and Access Key Secret. Access Key ID and Access Key Secret are available from the console; while Region ID is available in Region List.

Thank you! We've received your feedback.