全部產品
Search
文件中心

ApsaraVideo Live:.NET SDK使用說明

更新時間:Aug 13, 2025

本文介紹ApsaraVideo for Live服務端.NET SDK的使用方法和範例程式碼。

環境要求

.Net Framework >= 4.5 或 .Net Core >= 2.0。

操作步驟

  1. 引入SDK。

    1. 登入。

    2. 安裝頁面,所有語言選擇.NET。在快速入門頁簽中,您可以擷取ApsaraVideo for Live的SDK安裝方式。

      image

  2. 建立專案工程,並使用Credentials工具管理訪問憑證。具體詳情,請參見管理訪問憑證

  3. 發起請求並處理應答或異常。

    // This file is auto-generated, don't edit it. Thanks.
    
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using System.Threading.Tasks;
    
    using Tea;
    using Tea.Utils;
    
    
    namespace AlibabaCloud.SDK.Sample
    {
        public class Sample 
        {
    
            /// <term><b>Description:</b></term>
            /// <description>
            /// <para>使用憑據初始化帳號Client</para>
            /// </description>
            /// 
            /// <returns>
            /// Client
            /// </returns>
            /// 
            /// <term><b>Exception:</b></term>
            /// Exception
            public static AlibabaCloud.SDK.Live20161101.Client CreateClient()
            {
                // 工程代碼建議使用更安全的無AK方式,憑據配置方式請參見:https://www.alibabacloud.com/help/document_detail/378671.html。
                Aliyun.Credentials.Client credential = new Aliyun.Credentials.Client();
                AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
                {
                    Credential = credential,
                };
                // Endpoint 請參考 https://api.aliyun.com/product/live
                config.Endpoint = "live.aliyuncs.com";
                return new AlibabaCloud.SDK.Live20161101.Client(config);
            }
    
            public static void Main(string[] args)
            {
                AlibabaCloud.SDK.Live20161101.Client client = CreateClient();
                AlibabaCloud.SDK.Live20161101.Models.DescribeLiveDomainMappingRequest describeLiveDomainMappingRequest = new AlibabaCloud.SDK.Live20161101.Models.DescribeLiveDomainMappingRequest
                {
                    RegionId = "<Your RegionId>",
                    DomainName = "<Your DomainName>",
                };
                AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
                try
                {
                    // 複製代碼運行請自行列印 API 的傳回值
                    client.DescribeLiveDomainMappingWithOptions(describeLiveDomainMappingRequest, runtime);
                }
                catch (TeaException error)
                {
                    // 此處僅做列印展示,請謹慎對待異常處理,在工程專案中切勿直接忽略異常。
                    // 錯誤 message
                    Console.WriteLine(error.Message);
                    // 診斷地址
                    Console.WriteLine(error.Data["Recommend"]);
                    AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
                }
                catch (Exception _error)
                {
                    TeaException error = new TeaException(new Dictionary<string, object>
                    {
                        { "message", _error.Message }
                    });
                    // 此處僅做列印展示,請謹慎對待異常處理,在工程專案中切勿直接忽略異常。
                    // 錯誤 message
                    Console.WriteLine(error.Message);
                    // 診斷地址
                    Console.WriteLine(error.Data["Recommend"]);
                    AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
                }
            }
    
    
        }
    }