Blackberry PAP push


PAP push allow you to send push message using Blackberry Internet Service. This service uses XML .

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace pap_push
{
class push
{
public push(String param)
{
string pushId = “pushID:” + (new Random()).Next();
HttpWebResponse HttpWRes = null;
HttpWebRequest HttpWReq = null;
string pin = “2100000A”;
string BOUNDARY = “mPsbVQo0a68eIL3OAxnm”;
string msg = param;
string url = “http://localhost:8080/pap”;
HttpWReq = (HttpWebRequest)WebRequest.Create(url);
HttpWReq.Method = (“POST”);
HttpWReq.Accept = “text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2”;
HttpWReq.ContentType = “multipart/related; boundary=” + BOUNDARY + “;             type=application/xml”;
HttpWReq.Headers.Add(“x-Rim-Push-Dest-Port”, “100”);
HttpWReq.Headers.Add(“X-WAP-Application-id”, “/”);
StringBuilder dataToSend = new StringBuilder();
dataToSend.AppendLine(“–” + BOUNDARY);
dataToSend.AppendLine(“Content-Type: application/xml; charset=UTF-8”);
dataToSend.AppendLine(“”);
dataToSend.AppendLine(“<?xml version=\”1.0\”?>”);
dataToSend.AppendLine(“<!DOCTYPE pap PUBLIC \”-//WAPFORUM//DTD PAP 2.0//EN\” “);
dataToSend.AppendLine(“\”http://www.wapforum.org/DTD/pap_2.0.dtd\” “);
dataToSend.AppendLine(“[<?wap-pap-ver supported-versions=\”2.0\”?>]>”);
dataToSend.AppendLine(“<pap>”);
string myPushId = DateTime.Now.ToFileTime().ToString();
dataToSend.AppendLine(“<push-message push-id=\”” + pushId + “\” ppg-notify-requested-to=\”http://localhost:7778\”>”);
dataToSend.AppendLine(“<address address-value=\”WAPPUSH=” + pin + “%3A100/TYPE=USER@rim.net\” />”);
dataToSend.AppendLine(“<quality-of-service delivery-method=\”confirmed\” />”);
dataToSend.AppendLine(“</push-message>”);
dataToSend.AppendLine(“</pap>”);
dataToSend.AppendLine(“–” + BOUNDARY);
dataToSend.AppendLine(“Content-Type: text/plain”);
//dataToSend.AppendLine(“Push-Message-ID: ” + pushId);
dataToSend.AppendLine(“”);
dataToSend.AppendLine(msg);
dataToSend.AppendLine(“–” + BOUNDARY + “–“);
dataToSend.AppendLine(“”);
Stream requestStream = null;
string pushResult = “”;
try { requestStream = HttpWReq.GetRequestStream(); }
catch (Exception ex)
{
pushResult = “Push failed! ” + ex.ToString();
}
byte[] outStr = new ASCIIEncoding().GetBytes(dataToSend.ToString());
requestStream.Write(outStr, 0, outStr.Length);
requestStream.Close();
try
{
HttpWRes = (HttpWebResponse)HttpWReq.GetResponse();
}
catch (Exception ex)
{            //push failed
}
if (HttpWRes != null)
{
HttpWRes.Close();
}
}
}
}

Your device should access the rim url (http://www.rim.com) before the application able to listen the push.

About abunajiyah
A Programmer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: