Quantcast
Channel: Service Bus forum
Viewing all articles
Browse latest Browse all 1916

Event Hub: Unauthorized access. 'Send' claim(s) are required to perform this operation

$
0
0

I am receiving the following error when attempting to send telemetry to Event Hub using AMQP from an ASP.NET application.

Unauthorized access. 'Send' claim(s) are required to perform this operation. Resource: 'sb://changed-eh-ns.servicebus.windows.net/changed-eh'. TrackingId:7754266cd3f540099b6dda8ee0f66a10_G11,TimeStamp:12/7/2014 7:56:40 AM"

It seems pretty clear that I have some sort of authentication issue, but I've been unable to work out how to resolve it. I am trying to send from a ASP.NET web application.

namespace webns
{
    public partial class eventhubamqp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int sendCount = Convert.ToInt32(SendCount.SelectedValue);

            EventHubConnectSend(sendCount).Wait();
        }

        public async Task EventHubConnectSend(int sendCount)
        {
            var cs = @"Endpoint=sb://changed-eh-ns.servicebus.windows.net/;SharedAccessKeyName=EventHubListener;SharedAccessKey=0ZQ8Fp6nPfi1QFkXXXXXXb5NvBKEn1Am4B/n+zVq8LI=";

            var builder = new ServiceBusConnectionStringBuilder(cs)
                        {
                            TransportType = TransportType.Amqp
                        };

            var client = EventHubClient.CreateFromConnectionString(builder.ToString(), "changed-eh");

            for (int i = 0; i < sendCount; i++)
            {
                try
                {
                    var e = new Event
                    {
                        Message = "Test Message"
                    };

                    var serializedString = JsonConvert.SerializeObject(e);
                    var data = new EventData(Encoding.Unicode.GetBytes(serializedString))
                    {
                        PartitionKey = "0"
                    };

                    // Set user properties if needed
                    data.Properties.Add("Type", "Event");

                    await client.SendAsync(data).ConfigureAwait(false);
                }
                catch (Exception exp)
                {
                    Console.WriteLine("Error on send: " + exp.Message);
                }
            }

            return;
        }

    }

    [DataContract]
    public class Event
    {
        [DataMember]
        public string Message { get; set; }
    }

}

Glenn.


Viewing all articles
Browse latest Browse all 1916

Trending Articles