locked
How to get all devices registered programaticaly ? RRS feed

  • Question

  • By default getting only 100 devices through GetAllRegistrationsAsync that to only ios  and through tag wise not getting continuation token GetRegistrationsByTagAsync
    Tuesday, February 26, 2019 2:42 PM

All replies

  • GetAllRegistrationsAsync is not the maximum count of registrations. In order to use it, you will need to setup a loop.

    You'll need to use the ContinuationToken if you want beyond 100 registrations.

    Below is some sample code to achieve more than 100 registrations. Please let us know if you have further questions or concerns.

    internal async Task<List<RegistrationDescription>> GetAllRegisteredDevicesAsync()
    {
        var hub = NotificationHubClient.CreateClientFromConnectionString(
            Settings.Default.AzureNotificationsMobileAppFullSharedAccessListenerConnection,
            Settings.Default.AzureNotificationsMobileAppHubName,
            Settings.Default.AzureNotificationsTestSendMode);
    
        var allRegistrations = await hub.GetAllRegistrationsAsync(0);
        var continuationToken = allRegistrations.ContinuationToken;
        var registrationDescriptionsList = new List<RegistrationDescription>(allRegistrations);
        while (!string.IsNullOrWhiteSpace(continuationToken))
        {
            var otherRegistrations = await hub.GetAllRegistrationsAsync(continuationToken, 0);
            registrationDescriptionsList.AddRange(otherRegistrations);
            continuationToken = otherRegistrations.ContinuationToken;
        }
    
        return registrationDescriptionsList;
    }

    Wednesday, February 27, 2019 12:49 AM
  • Getting exception 

    "InnerException": {
    "Message": "An error has occurred.",
    "ExceptionMessage": "The remote server returned an error: (403) Forbidden.",
    "ExceptionType": "System.Net.WebException",
    "StackTrace": "   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)\r\n   at Microsoft.Azure.NotificationHubs.Messaging.ServiceBusResourceOperations.GetAllAsyncResult.<GetAsyncSteps>b__81(GetAllAsyncResult thisPtr, IAsyncResult r)\r\n   at Microsoft.Azure.NotificationHubs.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)"
    }
    "InnerException": {"Message": "An error has occurred.","ExceptionMessage": "The remote server returned an error: (403) Forbidden.","ExceptionType": "System.Net.WebException","StackTrace": " at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)\r\n at Microsoft.Azure.NotificationHubs.Messaging.ServiceBusResourceOperations.GetAllAsyncResult.<GetAsyncSteps>b__81(GetAllAsyncResult thisPtr, IAsyncResult r)\r\n at Microsoft.Azure.NotificationHubs.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)"}
    "InnerException": {"Message": "An error has occurred.","ExceptionMessage": "The remote server returned an error: (403) Forbidden.","ExceptionType": "System.Net.WebException","StackTrace": " at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)\r\n at Microsoft.Azure.NotificationHubs.Messaging.ServiceBusResourceOperations.GetAllAsyncResult.<GetAsyncSteps>b__81(GetAllAsyncResult thisPtr, IAsyncResult r)\r\n at Microsoft.Azure.NotificationHubs.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)"}
    "InnerException": {"Message": "An error has occurred.","ExceptionMessage": "The remote server returned an error: (403) Forbidden.","ExceptionType": "System.Net.WebException","StackTrace": " at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)\r\n at Microsoft.Azure.NotificationHubs.Messaging.ServiceBusResourceOperations.GetAllAsyncResult.<GetAsyncSteps>b__81(GetAllAsyncResult thisPtr, IAsyncResult r)\r\n at Microsoft.Azure.NotificationHubs.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)"}
    "InnerException": {"Message": "An error has occurred.","ExceptionMessage": "The remote server returned an error: (403) Forbidden.","ExceptionType": "System.Net.WebException","StackTrace": " at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)\r\n at Microsoft.Azure.NotificationHubs.Messaging.ServiceBusResourceOperations.GetAllAsyncResult.<GetAsyncSteps>b__81(GetAllAsyncResult thisPtr, IAsyncResult r)\r\n at Microsoft.Azure.NotificationHubs.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)"}
    Wednesday, February 27, 2019 5:43 AM
  • Several telemetry-related features, like exporting and importing registrations and telemetry access via APIs, are available only on the Standard service tier. If you attempt to use these features from the Free or Basic service tier, you receive an exception message if you use the SDK, and an HTTP 403 (Forbidden) error if you use the features directly from the REST APIs. To use telemetry-related features, first ensure in the Azure portal that you are using the Standard service tier.

    If you’re using a Free trier, you get 500 devices and 1 million pushes included per namespace per month – Refer this document for more details on the pricing tier feature offerings.

    Thursday, February 28, 2019 10:37 AM