Mariusz
Mariusz

Reputation: 442

Why have I UnauthorizedAccessException when I use Service Bus MessagingFactory?

I have configured authorization via certificate. When I use NamespaceManager to GetSubscription works fine, but when I try execute any method from MessagingFactory I receive System.UnauthorizedAccessException.

string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");

var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
SubscriptionDescription subscriptionDescription = namespaceManager.GetSubscription("testTopic", "testSubscription"); // executed properly

var messagingFactory = MessagingFactory.CreateFromConnectionString(connectionString);
var exist = namespaceManager.TopicExists("TestTopic"); // throws exception

Stack trace:

System.UnauthorizedAccessException was unhandled
  HResult=-2147024891
  Message=The remote server returned an error: (401) Unauthorized. Authorization failed for specified action: Manage..TrackingId:d8648c5a-5185-41c8-b787-72332403b7d9_*******,TimeStamp:2014-07-14 08:34:22
  Source=Microsoft.ServiceBus

What's the matter?

Upvotes: 2

Views: 4316

Answers (2)

csrowell
csrowell

Reputation: 924

You must be in the ManageUsers list in Service Bus Namespace or have the Authorization rule that gives you the Manage right on the Topic that you are getting the subscriptions for.

Upvotes: 1

Mariusz
Mariusz

Reputation: 442

For use NamespaceManager you must be in ManageUsers in Service Bus Namespace. To add user to existing namespace you can use ps Set-SBNamespace

Upvotes: 1

Related Questions