如何以编程方式检索 Azure 服务总线通知中心的连接字符串?

How do I programmatically retrieve the connection strings for a Azure Service Bus Notification Hub?

我有一个用于通知中心的服务总线。该服务总线上有多个通知中心。每个都有一对连接字符串,一个用于管理、监听、发送,一个用于监听。如何检索这些通知中心的连接字符串?我需要以编程方式而不是通过门户这样做。

这应该会告诉您如何操作。您需要通知中心命名空间的连接字符串才能开始...

NamespaceManager nsm = NamespaceManager.CreateFromConnectionString(connectionString);

var hubs = nsm.GetNotificationHubs();

foreach (NotificationHubDescription hub in hubs)
{
  foreach (SharedAccessAuthorizationRule rule in hub.Authorization)
  {
    Console.WriteLine("Hub Path: {0}, Key Name {1}, Primary Key: {2}", hub.Path, rule.KeyName, rule.PrimaryKey);
  }
}