Azure .Net SDK 用于生成 APIM 资源标识符/订阅

问题描述 投票:0回答:1

我正在查看这个 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"); 
azure-api-management azure-sdk-.net
1个回答
0
投票

你已经很接近了,你只需要继续前进。

这对我有用......

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

© www.soinside.com 2019 - 2024. All rights reserved.