edit-icon download-icon

Server Load Balancer

Last Updated: Mar 21, 2018

Alibaba Cloud Server Load Balancer (SLB) is a traffic distribution control service that distributes the incoming traffic among multiple Elastic Compute Service (ECS) instances according to the configured forwarding rules. It expands the service capabilities of the application and increases the availability of the application. For more information, see Server Load Balancer documentation.

This tutorial uses the CreateLoadBalancer API of SLB to show you how to use Alibaba Cloud C# SDK to call SLB APIs.

Note: Running the code in this example will create an SLB instance and generate fees.

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Profile;
  4. using Aliyun.Acs.Core.Exceptions;
  5. using Aliyun.Acs.Slb.Model.V20140515;
  6. class Sample
  7. {
  8. static void Main(string[] args)
  9. {
  10. // Create a client instance
  11. IClientProfile clientProfile = DefaultProfile.GetProfile("<your-region-id>", "<your-access-key-id>", "<your-access-key-secret>");
  12. DefaultAcsClient client = new DefaultAcsClient(clientProfile);
  13. try
  14. {
  15. // Create a request and set parameters
  16. CreateLoadBalancerRequest request = new CreateLoadBalancerRequest();
  17. request.LoadBalancerName = "my-sample-slb";
  18. request.AddressType = "internet";
  19. request.InternetChargeType = "paybytraffic";
  20. // Initiate the request and print the handling result
  21. CreateLoadBalancerResponse response = client.GetAcsResponse(request);
  22. Console.WriteLine("LoadBalancerId: {0}", response.LoadBalancerId);
  23. }
  24. catch (ServerException e)
  25. {
  26. Console.WriteLine(e.ErrorCode);
  27. Console.WriteLine(e.ErrorMessage);
  28. }
  29. catch (ClientException e)
  30. {
  31. Console.WriteLine(e.ErrorCode);
  32. Console.WriteLine(e.ErrorMessage);
  33. }
  34. }
  35. }
Thank you! We've received your feedback.