我正在查看这个 SDK 在我的 C# 应用程序中生成 APIM 订阅密钥。
我找不到获取类实例ApiManagementSubscriptionResource并调用此方法CreateResourceIdentifier(String, String, String, String)的正确方法。任何人都可以阐明如何调用方法从我的 C# 应用程序生成订阅密钥?
SubscriptionResource subscription = await client.GetDefaultSubscriptionAsync();
ResourceGroupCollection resourceGroups = subscription.GetResourceGroups();
ResourceGroupResource resourceGroup = await resourceGroups.GetAsync("rg_name");
var apiManagements = await resourceGroup.GetApiManagementServiceAsync("apim_name");
你已经很接近了,你只需要继续前进。
这对我有用......
var credential = new DefaultAzureCredential();
var armClient = new ArmClient(credential);
var subscription = await armClient.GetDefaultSubscriptionAsync();
var resourceGroups = subscription.GetResourceGroups();
var resourceGroup = await resourceGroups.GetAsync("rg-your-resource-group");
var apimInstance = await resourceGroup.Value.GetApiManagementServiceAsync("apim-your-instance");
var newSubscription = apimInstance.Value.GetApiManagementSubscriptions().CreateOrUpdate(Azure.WaitUntil.Completed, "your_generated_sid",
new Azure.ResourceManager.ApiManagement.Models.ApiManagementSubscriptionCreateOrUpdateContent()
{
DisplayName = "Display Name",
State = Azure.ResourceManager.ApiManagement.Models.SubscriptionState.Active,
Scope = "/products/Unlimited"
});
...您只需要计算出您的
Scope
、SID
、DisplayName
等