/aliyun-openapi-net-sdk

Alibaba Cloud SDK for .NET

Primary LanguageC#OtherNOASSERTION

English | 简体中文

Alibaba Cloud SDK for .NET

Travis Build Status Appveyor Build Status Codecov Nuget Version Nuget Version Nuget Version

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.

Troubleshoot

Troubleshoot Provide OpenAPI diagnosis service to help developers locate quickly and provide solutions for developers through RequestID or error message.

Online Demo

OpenAPI Workbench 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.

Requirements

  • The Alibaba Cloud SDK for .NET requires:
    • .NET Framework 4.5 and above
    • .NET Standard 2.0 and above
    • C# 4.0 and above

Installation

You should install ECS Nuget Package when you are using ECS Product. If you want to install a specific version, please add --version or it will install the latest version of this package.

Use .NET CLI ( Recommand )

dotnet add package aliyun-net-sdk-ecs

Use Package Manager

Install-Package aliyun-net-sdk-ecs

Quick Examples

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.

Initiate a call

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 the response.

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());
        }
    }
}

Documentation

Issues

Opening an Issue, Issues not conforming to the guidelines may be closed immediately.

Changelog

Detailed changes for each release are documented in the release notes.

API Reference

You can visit the API and its parameters in Product List.

License

Apache-2.0

FOSSA Status