English | 简体中文
The Alibaba Cloud SDK for .NET allows you to access Alibaba Cloud services such as Elastic Compute Service (ECS), Server Load Balancer (SLB), CloudMonitor, etc. You can access Alibaba Cloud services without the need to handle API related tasks, such as signing and constructing your requests.
OpenAPI Explorer provides the ability to call the cloud product OpenAPI online, generates SDK Example code dynamically and retrieves interface quickly, which can lessen the difficultly of using the Alibaba Cloud API significantly.
- The Alibaba Cloud SDK for .NET requires:
.NET Framework 4.6.1
or later.NET Standard 2.0
or later
You must install the SDK core Nuget Package for any SDK you use. For example, you should install both ECS Nuget Package and SDK Core Nuget Package when you are using ECS Product.
Use .NET CLI ( Recommand )
dotnet add package aliyun-net-sdk-core
dotnet add package aliyun-net-sdk-ecs
Use Package Manager
Install-Package aliyun-net-sdk-core
Install-Package aliyun-net-sdk-ecs
At the beginning, you need to sign up for an Alibaba Cloud account and retrieve your Credentials.
Note: To increase the security of your account, we recommend that you can use the AccessKey of the RAM user to access Alibaba Cloud services.
The following code example show three main steps to use the Alibaba Cloud SDK for .NET:
-
Create and initialize a
DefaultAcsClient
instance. -
Create a
request
and set parameters. -
Initiate the
request
and handle theresponse
.
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Ecs.Model.V20140526;
class Program
{
static void Main(string[] args)
{
// Create a client used for initiating a request
IClientProfile profile = DefaultProfile.GetProfile(
"<your-region-id>",
"<your-access-key-id>",
"<your-access-key-secret>");
DefaultAcsClient client = new DefaultAcsClient(profile);
try
{
// Create the request
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.PageSize = 10;
// Initiate the request and get the response
DescribeInstancesResponse response = client.GetAcsResponse(request);
System.Console.WriteLine(response.TotalCount);
}
catch (ServerException ex)
{
System.Console.WriteLine(ex.ToString());
}
catch (ClientException ex)
{
System.Console.WriteLine(ex.ToString());
}
}
}
Use BearerToken to invoke CCC Product
You should install the CCC Product Nuget Package if you want to run the below demo in your local machine.
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.CCC.Model.V20170705;
class Program
{
static void Main(string[] args)
{
// Create a client used for initiating a request
var profile = DefaultProfile.GetProfile("<your-region-id>");
var bearerTokenCredentialProvider = new BearerTokenCredentialProvider("<your-bearertoken>");
var client = new DefaultAcsClient(profile, bearerTokenCredentialProvider);
try
{
// Create the request
var request = new ListPhoneNumbersRequest();
// Initiate the request and get the response
var response = client.GetAcsResponse(request);
//Do something as you want below
}
catch (ServerException ex)
{
System.Console.WriteLine(ex.ToString());
}
catch (ClientException ex)
{
System.Console.WriteLine(ex.ToString());
}
}
}
Opening an Issue, Issues not conforming to the guidelines may be closed immediately.
Detailed changes for each release are documented in the release notes.
You can visit the API and its parameters in Product List.