0
votes

It really amazes me that a company like Microsoft doesn't give you readable error messages. I'm simply trying to register a device into a notification hub in our azure.

if (App.DeviceInfo.DeviceManufacturer == "Apple")
{
    if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
    {
        var pushSettings = UIUserNotificationSettings.GetSettingsForTypes(
               UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
               new NSSet());

        UIApplication.SharedApplication.RegisterUserNotificationSettings(pushSettings);
        UIApplication.SharedApplication.RegisterForRemoteNotifications();
    }
    else
    {
        UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
        UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
    }
}

Register callback

public override void RegisteredForRemoteNotifications(UIApplication app, NSData deviceToken)
{
    //// Connection string from your azure dashboard
    var cs = WindowsAzure.Messaging.SBConnectionString.CreateListenAccess(
        new NSUrl(AzureServiceBusConnectionString),
        AzureHubName);

    // Register our info with Azure
    var hub = new WindowsAzure.Messaging.SBNotificationHub(cs, AzureHubName);
    hub.RegisterNativeAsync(deviceToken, null, err =>
    {
        if (err != null)
        {
            Console.WriteLine("Error: " + err.Description);
            Console.WriteLine(err.DebugDescription);
        }
        else
            Console.WriteLine("Success");
    });
}

Here's the error message I get back

Error: Error Domain=WindowsAzureMessaging Code=401 "URLRequest failed for { URL: https://****.servicebus.windows.net/****/Registrations/?$filter=deviceToken+eq+'****'&api-version=2013-04 } with status code: unauthorized" UserInfo={NSLocalizedDescription=URLRequest failed for { URL: https://****.servicebus.windows.net/newsernotificationhub/Registrations/?$filter=deviceToken+eq+'****'&api-version=2013-04 } with status code: unauthorized}

So the only message I get back is unauthorized, just wondering what some of the reasons why it would come back as unauthorized when I'm using the endpoint url given in azure, and the notification hub name.

1
Could you go through diagnosis guidelines and update the question if something still doesn't work? First it's important to understand whether the issue is on the service side or on the client code side. At the moment it sounds like more on the client. Possibly wrong hub credentials were provided.Nikita R.
Well there is no client side. I'm registering the device server side in my Xamarin app. Trying to talk to azure notification hub to register a device. I'm not sure how that page helps, I think that might be dealing with actually sending the notification? Could be wrong, but that's what I'm understanding.jdmdevdotnet
"Failure to deliver notifications may happen during the initial test/staging phase which may indicate a configuration issue or it may happen in production where either all or some of the notifications may be getting dropped indicating some deeper application or messaging pattern issue. " this deals with diagnosing notifications that didn't get delivered. Nothing to do with my issue.jdmdevdotnet

1 Answers

0
votes

My issue was with some of the documentation I saw which tells you to do this

//// Connection string from your azure dashboard
var cs = WindowsAzure.Messaging.SBConnectionString.CreateListenAccess(
   new NSUrl(AzureServiceBusConnectionString),
   AzureHubName);

// Register our info with Azure
var hub = new WindowsAzure.Messaging.SBNotificationHub(cs, AzureHubName);

When really all that's necessary is this

var hub = new WindowsAzure.Messaging.SBNotificationHub(AzureServiceBusConnectionString, AzureHubName);

So when you're instantiating a new SBNotificationHub, you just supply the connection string and hub name. Without doing the CreateListenAccess