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

Call to NotificationHub.RegisterNativeAsync() throws RegistrationMismatchedETagException

$
0
0

Hi all,

I'm trying to add toast notifications to my Windows Phone 8 app using a Service Bus Notification Hub. My implementation is based on this tutorial but the code in my app have been slightly restructured.

The toast notifications works fine to begin with. My backend is able create the notification and it is received and displayed by the phone. However after the app has been starter a number of times (varies) a RegistrationMismatchedETagException exception is thrown from the call to NotificationHub.RegisterNativeAsync(). When it first starts happening then all calls to the method throws the exception. Only way to get rid of it is to uninstall and reinstall the app.

The full exception details is:

--------

HTTP request failed.

HTTP Details:
Status: 412
Reason: Precondition Failed
Full content: <Error><Code>412</Code><Detail>The ETag header is either missing or invalid. It should be "*", or a quoted ETag..TrackingId:56aaf5ae-573f-4310-bdaf-2a7c857916ea_G11,TimeStamp:12/2/2013 10:21:40 AM</Detail></Error>

--------

and the stack trace is:

--------

   at Microsoft.WindowsAzure.Messaging.Http.Internal.HttpChannel.ProcessResponse(HttpResponse response, Func`2[] handlers)
   at Microsoft.WindowsAzure.Messaging.Http.Internal.HttpChannel.<>c__DisplayClass4.<SendAsyncInternal>b__3(Task`1 t)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

--------

The problem occurs on both an actual device and in the emulator.

The relevant part of my mobile phone code is:

        private static NotificationHub _notificationHub = new NotificationHub(<name of the notification hub>, <DefaultListenSharedAccessSignature of the notification hub>);
        private static HttpNotificationChannel _httpNotificationChannel;

        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            _httpNotificationChannel = HttpNotificationChannel.Find("MyPushChannel");
            if (_httpNotificationChannel == null)
            {
                _httpNotificationChannel = new HttpNotificationChannel("MyPushChannel");
                _httpNotificationChannel.Open();
                _httpNotificationChannel.BindToShellToast();
            }
            _httpNotificationChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
            {
                await UpdateNotificationHubNotifications();
            });
        }

        public static async Task UpdateNotificationHubNotifications()
        {
            if (_httpNotificationChannel.ChannelUri != null)
            {
                List<string> tags = new List<string>();
                tags.Add("user:all");
                if (!string.IsNullOrWhiteSpace(Settings.Instance.Username))
                {
                    tags.Add("user:" + Settings.Instance.UserId);
                }
                try
                {
                    await _notificationHub.RegisterNativeAsync(_httpNotificationChannel.ChannelUri.ToString(), tags);
                }
                catch (Exception e)
                {
                    MessageBox.Show("Exception calling RegisterNativeAsync(): " + e.Message);
                }
            }
        }

Note that the UpdateNotificationHubNotifications() methos id called not only from the HttpNotificationChannel.ChannelUriUpdated event handler but also when the app is started and when the user logs in and out.I have searched the web for RegistrationMismatchedETagException and have not found anybody else that has the same problem. And also it puzzles me that it works to begin with but then after two or three app restarts it starts throwing the exception.

All help will be strongly appreciated.

Thanks

Jimmi


Viewing all articles
Browse latest Browse all 1916

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>