我正在将Azure Management libraries for .NET与Azure Service Bus一起使用。我的目标是使用 Send 和 Listen 声明创建共享访问策略。我可以在Azure门户中做到这一点。
IServiceBusNamespace serviceBus = ...
IBlank policyDefinition = serviceBus.AuthorizationRules.Define("MySendAndListenPolicy2");
在IBlank
中,我可以呼叫WithListeningEnabled()
或WithSendingEnabled()
。两者都返回一个IWithCreate
,我只能从中创建规则(即Create()
和CreateAsync()
。似乎没有一个选项可以同时配置 Send 和 Listen 。
如何使用Azure Management .NET SDK通过发送和收听创建策略?
答案 0 :(得分:1)
我已经通过使用流畅的API的内部对象实现了这一目标。
// using Microsoft.Azure.Management.Fluent;
// using Microsoft.Azure.Management.ServiceBus.Fluent;
// using Microsoft.Azure.Management.ServiceBus.Fluent.Models;
string policyName = "ListenAndSendPolicy";
// Define the claims
IList<AccessRights?> rights = new List<AccessRights?>();
rights.Add(AccessRights.Send);
rights.Add(AccessRights.Listen);
// Create the rule
SharedAccessAuthorizationRuleInner rule = await serviceBus.AuthorizationRules.Inner.CreateOrUpdateAuthorizationRuleAsync(
serviceBus.ResourceGroupName,
serviceBus.Name,
policyName,
rights);
// Get the policy
policy = await serviceBus.AuthorizationRules.GetByNameAsync(policyName);
这成功创建了政策