Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry Push Development

Reply
Regular Contributor
Posts: 97
Registered: ‎09-21-2010
My Device: 8900
My Carrier: developer

Push Notification from client side

Hi there,

 

I have implemented server side code successfully in ASP.net, but i am not able to retrieve message in my device.

 

My server side code is: 

 public bool pushToWidget(string pushedMessage, string pushPin)
        {
            String BESAddress = "https://pushapi.eval.blackberry.com/mss/PD_pushRequest";
            String BESWebserverListenPort = "pushPort";
            String widgetNotificationUrl = "https://pushapi.eval.blackberry.com/mss/PD_pushRequest";
            String pushUserName = "pushUserName";
            String pushPassword = "pushPassword";
            String pushPort = "pushPort ";
            string Boundary = "Boundary ";
            string DeliverBefore = DateTime.UtcNow.AddMinutes(5).ToString("s", 

System.Globalization.CultureInfo.InvariantCulture) + "Z";
            Response.Write(DeliverBefore);
            bool success = true;
            StringBuilder Data = new StringBuilder();
            Data.AppendLine("--" + Boundary);
            Data.AppendLine("Content-Type: application/xml; charset=utf-8");
            Data.AppendLine("");
            Data.AppendLine("<?xml version=\"1.0\"?>");
            Data.AppendLine("<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP 2.1//EN\">");
            Data.AppendLine("<pap>");
            Data.AppendLine("<push-message push-id=" + (char)34 + ID + (char)34 + " deliver-before-timestamp=" + 

(char)34 + DeliverBefore + (char)34 + " source-reference=" + (char)34 + pushUserName + (char)34 + ">");
            Data.AppendLine("<address address-value=\"" + pushPin + "\"/>");
            Data.AppendLine("<quality-of-service delivery-method=\"unconfirmed\"/>");
            Data.AppendLine("</push-message>");
            Data.AppendLine("</pap>");
            Data.AppendLine("--" + Boundary);
            Data.AppendLine("Content-Type: text/plain");
            Data.AppendLine("Push-Message-ID: " + ID);
            Data.AppendLine("");
            Data.AppendLine(pushedMessage);
            Data.AppendLine("--" + Boundary + "--");
            Data.AppendLine("");
            byte[] bytes = Encoding.ASCII.GetBytes(Data.ToString());

            Stream requestStream = null;
            HttpWebResponse HttpWRes = null;
            HttpWebRequest HttpWReq = null;
          
            try
            {
                //http://<BESName>:<BESPort>/push?

DESTINATTION=<PIN/EMAIL>&PORT=<PushPort>&REQUESTURI=/
                // Build the URL to define our connection to the BES.
                string httpURL = BESAddress + ":" + BESWebserverListenPort
                    + "/push?DESTINATION=" + pushPin + "&PORT=" + pushPort
                    + "&REQUESTURI=/";
                   
                //make the connection
                HttpWReq = (HttpWebRequest)WebRequest.Create(httpURL);
                HttpWReq.Method = ("POST");
                //add the headers nessecary for the push
                HttpWReq.ContentType = "text/plain";
                HttpWReq.ContentLength = bytes.Length;
                // ******* Test this *******
                HttpWReq.Headers.Add("X-Rim-Push-Id", pushPin + "~" + DateTime.Now); //"~" +pushedMessage +
                HttpWReq.Headers.Add("X-Rim-Push-Reliability", "application-preferred");
                HttpWReq.Headers.Add("X-Rim-Push-NotifyURL", (widgetNotificationUrl + pushPin + "~" + pushedMessage 

+ "~" + DateTime.Now).Replace(" ", ""));

                // *************************
               
                HttpWReq.Credentials = new MDSCredentials(pushUserName, pushPassword);
                Console.WriteLine(pushedMessage);
                requestStream = HttpWReq.GetRequestStream();
                //Write the data from the source
                requestStream.Write(bytes, 0, bytes.Length);
                requestStream.Close();
                //get the response
                HttpWRes = (HttpWebResponse)HttpWReq.GetResponse();

                //if the MDS received the push parameters correctly it will either respond with okay or accepted
                if (HttpWRes.StatusCode == HttpStatusCode.OK || HttpWRes.StatusCode == HttpStatusCode.Accepted)
                {
                    success = true;
                }
                else
                {
                    success = false;
                }
                //Close the streams

                HttpWRes.Close();
                requestStream.Close();
            }
            catch (System.Exception e)
            {
                success = false;
            }

            return success;
        }
 

 

I tried HttpPushDemo sample from JDE but it dose not work and i am unable to recieve any message or notification when we push message from server.

I had also tried PushAgent.java and PushMessageReader.java in project, we are passing device token statically from server.

 

Please help me out from this problem, I tried a lot but I was not able to fix this issue.

 

Regards,

 

Amrinder Singh

 

Regular Contributor
Posts: 97
Registered: ‎09-21-2010
My Device: 8900
My Carrier: developer

Re: Push Notification from client side

Please help
Regular Contributor
Posts: 97
Registered: ‎09-21-2010
My Device: 8900
My Carrier: developer

Re: Push Notification from client side

Hi,

 

 

Please help me to get rid from this problem , i am still stuck on this issue. 

 

Regards, 

Amrinder Singh