For my environment, I use Rest API to register/unregister my device with notification hub.
Whenever my user logs in, my app registers with GCM, gets a registration ID, then registers with notification hub to receive notification. This works without any problem.
When my user logs out, my app wants to delete that registration from notification hub so user will not longer receive any notification.
After consulting this page on how to Delete Registration
https://msdn.microsoft.com/en-us/library/azure/dn223268.aspx
I wrote the following code:
var client = new XMLHttpRequest();
client.onload = function () {
if (client.readyState == 4) {
if (client.status == 200) {
// we are logged out
console.log("(sendNHDeleteRegistrationRequest) NH delete registration is successful");
chrome.storage.local.set({registered: false});
updateRegisterUI();
} else {
console.log("(sendNHDeleteRegistrationRequest) NH delete registration is not successful");
console.log("(sendNHDeleteRegistrationRequest) HTTP Status: " + client.status + " : " + client.statusText);
console.log("(sendNHDeleteRegistrationRequest) HTTP Response: " + "\n" + client.responseText);
}
}
};
var url = gOriginalUri + "/registrations/" + gRegistrationId + "?api-version=2015-01";
client.open("POST", url, true);
client.setRequestHeader("Content-Type", "application/atom+xml;type=entry;charset=utf-8");
client.setRequestHeader("Authorization", gSasToken);
client.setRequestHeader("x-ms-version", "2015-01");
try {
client.send();
chrome.storage.local.set({registered: false});
updateRegisterUI();
}
catch(err) {
console.log(err.message);
}
But I always receive this error:
(sendNHDeleteRegistrationRequest) NH delete registration is not successful
register.js:230 (sendNHDeleteRegistrationRequest) HTTP Status: 405 : Method Not Allowed
register.js:231 (sendNHDeleteRegistrationRequest) HTTP Response:
405The specified HTTP verb (POST) is not valid..TrackingId:64cd952b-ffda-42f8-860b-22dd4aa397ea_G3,TimeStamp:7/31/2015 4:00:48 AM
so my question is 1. To stop receiving notification for my app when user logs out, what's the standard practice? Block the notification from firing in the app or delete the registration from the notification hub? 2. Am I using this delete registration the right way?Why am I receiving 405 Method not allowed?
thanks!