private static async Task <string> GetPlatformNotificationServiceFeedbackContainer(string hubName, string connectionString)
        {
            HttpWebResponse         response          = null;
            ConnectionStringUtility connectionSasUtil = new ConnectionStringUtility(connectionString);

            string hubResource = "feedbackcontainer?";
            string apiVersion  = "api-version=2015-04";

            //=== Generate SaS Security Token for Authentication header ===
            // Determine the targetUri that we will sign
            string uri = connectionSasUtil.Endpoint + hubName + "/" + hubResource + apiVersion;

            // 10 min expiration
            string SasToken = connectionSasUtil.getSaSToken(uri, 10);

            response = await ExecuteREST("GET", uri, SasToken);

            if ((int)response.StatusCode != 200)
            {
                return(string.Format("Failed to get PNS feedback contaioner URI - Http Status {0} : {1}",
                                     (int)response.StatusCode, response.StatusCode));
            }

            // Get the stream associated with the response.
            Stream receiveStream = response.GetResponseStream();

            // Pipes the stream to a higher level stream reader with the required encoding format.
            StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);

            Console.WriteLine("");
            string containerUri = readStream.ReadToEnd();

            readStream.Close();
            receiveStream.Close();
            return(containerUri);
        }
        private static async Task <string> SendNativeNotificationREST(string hubname, string connectionString, string message, string nativeType)
        {
            ConnectionStringUtility connectionSaSUtil = new ConnectionStringUtility(connectionString);
            string location = null;

            string hubResource    = "messages/?";
            string apiVersion     = "api-version=2015-04";
            string notificationId = "Failed to get Notification Id";

            //=== Generate SaS Security Token for Authentication header ===
            // Determine the targetUri that we will sign
            string uri = connectionSaSUtil.Endpoint + hubname + "/" + hubResource + apiVersion;

            // 10 min expiration
            string SasToken = connectionSaSUtil.getSaSToken(uri, 10);

            WebHeaderCollection headers = new WebHeaderCollection();
            string          body;
            HttpWebResponse response = null;

            switch (nativeType.ToLower())
            {
            case "apns":
                headers.Add("ServiceBusNotification-Format", "apple");
                body     = "{\"aps\":{\"alert\":\"" + message + "\"}}";
                response = await ExecuteREST("POST", uri, SasToken, headers, body);

                break;

            case "gcm":
                headers.Add("ServiceBusNotification-Format", "gcm");
                body     = "{\"data\":{\"message\":\"" + message + "\"}}";
                response = await ExecuteREST("POST", uri, SasToken, headers, body);

                break;

            case "wns":
                headers.Add("X-WNS-Type", "wns/toast");
                headers.Add("ServiceBusNotification-Format", "windows");
                body = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
                       "<toast>" +
                       "<visual>" +
                       "<binding template=\"ToastText01\">" +
                       "<text id=\"1\">" +
                       message +
                       "</text>" +
                       "</binding>" +
                       "</visual>" +
                       "</toast>";
                response = await ExecuteREST("POST", uri, SasToken, headers, body, "application/xml");

                break;
            }

            char[] seps1 = { '?' };
            char[] seps2 = { '/' };

            if ((int)response.StatusCode != 201)
            {
                return(string.Format("Failed to get notification message id - Http Status {0} : {1}", (int)response.StatusCode, response.StatusCode.ToString()));
            }

            location = response.Headers.Get("Location");
            string[] locationUrl   = location.Split(seps1);
            string[] locationParts = locationUrl[0].Split(seps2);

            notificationId = locationParts[locationParts.Length - 1];

            return(notificationId);
        }
        private static async Task <string> SendNativeNotificationREST(string hubName, string connectionString, string message, string title, string nativeType, string tag)
        {
            var connectionSaSUtil = new ConnectionStringUtility(connectionString);

            var hubResource = "messages/?";
            var apiVersion  = "api-version=2015-04";

            //=== Generate SaS Security Token for Authentication header ===
            // Determine the targetUri that we will sign
            var uri = connectionSaSUtil.Endpoint + hubName + "/" + hubResource + apiVersion;

            // 10 min expiration
            var sasToken = connectionSaSUtil.GetSaSToken(uri, 10);

            WebHeaderCollection headers = new WebHeaderCollection();
            string          body;
            HttpWebResponse response = null;

            switch (nativeType.ToLower())
            {
            case "ios":
                headers.Add("ServiceBusNotification-Format", "apple");
                headers.Add("ServiceBusNotification-Tags", tag);
                body     = "{\"aps\":{\"alert\":{\"title\":\"" + title + "\", \"body\":\"" + message + "\"}}}";
                response = await ExecuteREST("POST", uri, sasToken, headers, body);

                break;

            case "android":
                headers.Add("ServiceBusNotification-Format", "gcm");
                headers.Add("ServiceBusNotification-Tags", tag);
                body     = "{\"data\":{\"title\":\"" + title + "\", \"body\":\"" + message + "\", \"priority\":\"high\"}}";
                response = await ExecuteREST("POST", uri, sasToken, headers, body);

                break;
            }

            if (response != null && response.StatusCode == HttpStatusCode.Created)
            {
                return("Notification successfully sent");
            }
            else if (response != null && response.StatusCode == HttpStatusCode.BadRequest)
            {
                return("The request is malformed (for example, not valid routing headers, not valid content-type, message exceeds size, bad message format)");
            }
            else if (response != null && response.StatusCode == HttpStatusCode.Unauthorized)
            {
                return("Authorization failure. The access key was incorrect.");
            }
            else if (response != null && response.StatusCode == HttpStatusCode.Forbidden)
            {
                return("Quota exceeded or message too large; message was rejected.");
            }
            else if (response != null && response.StatusCode == HttpStatusCode.NotFound)
            {
                return("No message branch at the URI.");
            }
            else if (response != null && response.StatusCode == HttpStatusCode.RequestEntityTooLarge)
            {
                return("Requested entity too large. The message size cannot be over 64 Kb.");
            }

            return(null);
        }