How to Create Queue in Windows Azure?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 07:39:24

问题


I am using below code to create queue, using SharedSecretTokenProvider. However I am not able to supply correct values of managerName & managerKey value form windows azure portal.

This results in Http 401 Unauthorized exception. How do I resolve this error?

const string queueName = "thequeue";
var tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(
    ConfigurationManager.AppSettings["managerName"],
    ConfigurationManager.AppSettings["managerKey"]);

Uri uri = ServiceBusEnvironment.CreateServiceUri("http", "MyNamespace" , string.Empty);
NamespaceManager namespaceManager = new NamespaceManager(uri, tokenProvider);

QueueDescription qd = namespaceManager.CreateQueue(new QueueDescription(queueName)
{
    DefaultMessageTimeToLive = TimeSpan.FromMinutes(15),
    DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(10),
    LockDuration = TimeSpan.FromMinutes(2),
    EnableBatchedOperations = true,
    EnableDeadLetteringOnMessageExpiration = true,
    RequiresDuplicateDetection = true
});


回答1:


I had tried this a couple of times with your code before I realized the problem. You are using the SharedSecretTokenProvider which will go to ACS thinking it has an issuer and a key. Since you are trying to use the SAS you'll want to use a CreateSharedAccessSignatureTokenProvider instead.

Swap that out and provide the key and keyName and you should be good.

Also, Viperguynaz is correct, you should use the "sb" instead of http as well. It was failing before it reached there because the token provider was correctly declining you access since it didn't understand the key and keyname you were passing for what it thought was the issuer and key that ACS uses.




回答2:


Start with ServiceBusEnvironment.CreateServiceUri Method. Note that Service Bus endpoint URIs must always use the “sb://” protocol; for example sb://contoso.servicebus.windows.net/helloservicebus.

Uri address = ServiceBusEnvironment.CreateServiceUri("sb", "contoso", "helloservicebus");

Get your URI inputs set correctly and you should be in business.



来源:https://stackoverflow.com/questions/18032506/how-to-create-queue-in-windows-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!