All Products
Search
Document Center

Alibaba Cloud SDK:Get started with Alibaba Cloud Darabonba SDK for .NET

Last Updated:Jan 10, 2024

This topic describes how to install the environment for using Alibaba Cloud Darabonba SDK for .NET and run the sample code to call an API operation.

Preparations

Prerequisites

  • .NET Framework 4.5 or later is downloaded and installed. To download the required.NET version, go to the Download .NET page on the .NET official website.

  • .NET Standard 2.0 or later is downloaded and installed.

  • C# 4.0 or later is installed.

  • An integrated development environment (IDE) is downloaded and installed. In this topic, Visual Studio is used. To download Visual Studio, go to the Visual Studio download page on the Microsoft official website.

  • An AccessKey pair is created. When you call an API operation, you must use an AccessKey pair to complete identity authentication. An AccessKey pair consists of an AccessKey ID and an AccessKey secret. For more information about how to create an AccessKey pair, see Create an AccessKey pair.

  • .NET version

    Run the dotnet --version command on the terminal to check the .NET version.

Run the sample code

Step 1: Download an SDK project

  1. Log on to OpenAPI Explorer.

  2. In the top navigation bar, click Select a cloud service. In the panel that appears, select the cloud service that you want to manage. The page of the selected cloud service appears.

  3. In the top navigation bar, click API Debugging. Then, a page with three columns appears.

    image.png

  4. Select the API operation that you want to call in the leftmost column. Configure the required parameters in the middle column. Then, click the SDK Sample Code tab in the rightmost column.

  5. Select V2.0 from the SDK Version drop-down list. Select a programming language based on your business requirements.

  6. Click Download Project to download the sample code.

  7. If you want to generate generic code, turn on Common Request. For more information, see Generic calls and specialized calls.

Step 2: Configure environment variables

Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.

  • If you use a Linux or macOS operating system, perform the following operations:

    • Create the .bash_profile file.

      Note

      If you configure environment variables for the first time, you can run the touch ~/.bash_profile command to create the configuration file. If the configuration file already exists, run the vim ~/.bash_profile command.

      touch .bash_profile
      vim ~/.bash_profile
    • Configure the .bash_profile file.

      # Replace <ACCESS_KEY_ID> and <ACCESS_KEY_SECRET> in the following commands with your AccessKey ID and AccessKey secret. 
      export ALIBABA_CLOUD_ACCESS_KEY_ID=<ACCESS_KEY_ID>
      export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<ACCESS_KEY_SECRET>
    • Use the .bash_profile file.

      # Run the commands in the configuration file.
      source ~/.bash_profile
      # Check whether the configuration takes effect.
      echo $ALIBABA_CLOUD_ACCESS_KEY_ID
  • If you use a Windows operating system, create a file to add the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables, and set the variables to your AccessKey ID and AccessKey secret.

Restart the IDE. Otherwise, the environment variables may fail to be read.

Step 3: Run the code

  1. Run the code in Visual Studio. After the code is run, view the returned information and request ID in the body of console logs.

  2. If you call an API operation to create an instance, the instance ID is also returned. You can log on to the console of the Alibaba Cloud service to verify the returned information based on the instance ID.