This document introduces how to install and call Alibaba Cloud .NET SDK.
Install .NET SDK
Add DLL reference
Download the DLL package from .NET SDK.
Right click your project in the Solution Explorer of Visual Studio and click Reference.
In the displayed menu, click Add Reference.
In the displayed dialog box, click Browse. Then select the downloaded DLL file and click Confirm.
Add project reference
Run the following command to clone the SDK source codes from GitHub.
git clone https://github.com/aliyun/aliyun-openapi-net-sdk.git
There are many folders prefixed with aliyun-net-openapi-XXXin the cloned directory. Each folder contains the \\*.csproj file, which is the .NET project file. For example, there is an
aliyun-net-sdk-ecs.csprojfile under the
In Visual Studio, right click your solution.
In the displayed dialog box, select the project file, for example,
aliyun-net-sdk-ecs.csproj, and click then Open.
Right click your project and click.
When using the Alibaba Cloud .NET SDK to access Alibaba Cloud services, you need an Alibaba Cloud account for authentication.
Currently, .NET SDK supports the following authentication methods:
Use the AccessKey to complete the authentication.
Use the STS Token to complete the authentication.
Use the AssumeRole of the RAM account to complete the authentication.
Use the RAM role of an ECS instance to complete the authentication.
This document uses AccessKey as an example to illustrate how to set up credentials. To ensure the security of your account, we recommend using your RAM account instead of the primary account. The primary account has full access to all of your cloud services, while the RAM account has limited access granted by the primary account to the cloud services. Firstly, create an AccessKey as described, and then set up your credentials when initializing the Client as follows:
Do not disclose any code containing your AccessKey (do not commit the code to public GitHub projects). Otherwise, your Alibaba Cloud account may be compromised.
IClientProfile clientProfile = DefaultProfile.GetProfile( "<your-region-id>", // region ID "<your-access-key-id>", // AccessKey ID of RAM account "<your-access-key-secret>"); // AccessKey Secret of RAM account
Initiate a call
This document takes ECS as an example to introduce how to use Alibaba Cloud .NET SDK to initiate a request.
Creates a default client instance.
DefaultAcsClient client = new DefaultAcsClient(clientProfile);
Create a request.
The naming convention for requests is
is the API name, such as DescribeInstances.
When multiple product SDKs are used, different requests may have the same name. Differentiate the requests according to the package.
DescribeInstancesRequest request = new DescribeInstancesRequest(); request.PageSize = 10;
Initiate a call and process the response.
DescribeInstancesResponse response = client.GetAcsResponse(request);
Normally, all fields in the response will be deserialized to the response. You can obtain the fields in the response by calling