This topic describes how to use the server SDK for .NET.

Prerequisites

.NET Framework 4.5 or later is installed.

Procedure

  1. Install the server SDK for .NET.
    1. Download and decompress the server SDK for .NET. For more information, see SDK download.
    2. In Solution Explorer of Microsoft Visual Studio, right-click your project and choose Add > Reference.
    3. In the Reference Manager dialog box, click Browse, select the extracted .dll file, and then click Add.
    4. Click OK.
  2. Create a DefaultAcsClient instance and initialize it.
    DefaultAcsClient client = new DefaultAcsClient(clientProfile);
  3. Create an API request and set the request parameters.
    // Create a request.
    DescribeInstancesRequest request = new DescribeInstancesRequest();
    request.PageSize = 10;
  4. Send the request and process the success or error response.
    using Aliyun.Acs.Core;
    using Aliyun.Acs.Core.Profile;
    using Aliyun.Acs.Core.Exceptions;
    using Aliyun.Acs.Ecs.Model.V20140526;
    
    class TestProgram
    {
        static void Main(string[] args)
        {
            // Create a client to send a request.
            IClientProfile profile = DefaultProfile.GetProfile(
                "<your-region-id>",
                "<your-access-key-id>",
                "<your-access-key-secret>");
            DefaultAcsClient client = new DefaultAcsClient(profile);
            try
            {
                // Create a request.
                DescribeInstancesRequest request = new DescribeInstancesRequest();
                request.PageSize = 10;
                // Send the request and obtain 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());
            }
        }
    }