The server operation SDK for .NET can be initialized by using an AccessKey pair. This topic describes how to initialize the server operation SDK for .NET by using an AccessKey pair and how to troubleshoot the error that occurs when you call operations by using the SDK.
Prerequisites
- The server operation SDK for .NET is installed. For more information, see Installation.
-
A region is specified for using ApsaraVideo VOD. For example, if you use ApsaraVideo VOD in the China (Shanghai) region, the region ID is
cn-shanghai
. For more information, see VOD centers and endpoints.
Initialize the SDK
Obtain an AccessKey pair to complete identity verification so that you can call server API operations. For more information about how to obtain an AccessKey pair, see Obtain an AccessKey pair.
Use the AccessKey pair to initialize the SDK. The following sample code provides an example:
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
public static DefaultAcsClient InitVodClient(string accessKeyId, string accessKeySecret)
{
// Specify the region from which you want to access ApsaraVideo VOD.
string regionId = "cn-shanghai";
// Specify the AccessKey pair.
IClientProfile profile = DefaultProfile.GetProfile(regionId, accessKeyId, accessKeySecret);
// DefaultProfile.AddEndpoint(regionId, regionId, "vod", "vod." + regionId + ".aliyuncs.com");
return new DefaultAcsClient(profile);
}
Usage notes
SDK.InvalidRegionId, Can not find endpoint to access.
due to SDK compatibility issues. For more information about supported regions, see
VOD centers and endpoints. To fix this error, invoke the AddEndpoint
method that has been commented out in InitVodClient in the preceding example. The following sample code provides an example:using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
public static DefaultAcsClient InitVodClient(string accessKeyId, string accessKeySecret)
{
// Specify the region from which you want to access ApsaraVideo VOD.
string regionId = "cn-shanghai";
// Specify the AccessKey pair.
IClientProfile profile = DefaultProfile.GetProfile(regionId, accessKeyId, accessKeySecret);
DefaultProfile.AddEndpoint(regionId, regionId, "vod", "vod." + regionId + ".aliyuncs.com");
return new DefaultAcsClient(profile);
}