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
New Contributor
Posts: 5
Registered: ‎06-23-2010
My Device: Curve
My Carrier: Orange

C# push notification application (server side)

Hi,

I'm interesting in writing a c# (.Net) push application (server side).

I have few questions;

 

1. Is it possible to send push notification from a .Net application on a windows server?

2. What is the best way of doing so?

 

Thanks,

Janiv Ratson.

 

Developer
Posts: 482
Registered: ‎10-24-2008
My Device: 9300
My Carrier: AT&T

Re: C# push notification application (server side)

Janiv,

 

1.  It is possible. I have several C# push server side applications in production currently.

 

2. I have code samples all throughout this post

 

http://supportforums.blackberry.com/t5/BlackBerry-Push-Development/Pushing-to-application-push-and-f...

 

Let me know if you need any more assistance, but this should get you started.

_________________________________________
www.jasonmace.com/blackberry
New Contributor
Posts: 3
Registered: ‎05-09-2013
My Device: 9700
My Carrier: Airtel

Re: C# push notification application (server side)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Net;

namespace BlackberryPUSH
{
public partial class _Default : System.Web.UI.Page
{

 

protected void Page_Load(object sender, EventArgs e)
{
// pushMessage("hi", "220");

}


public void pushMessage(string pushedMessage, string pushPin)
{

string appid = "3457-B730k4394m49rOr96r33M8t74303c51k728";
string password = "smnBIWO3";

 


String BESAddress = "http://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;
}

}
}

 

This Code i wrote for sending NOtification from server side code is debugging and running properly and getting sucess response But not Getting notifcation in Blackberry Device 

Retired
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10
My Carrier: Rogers

Re: C# push notification application (server side)

Please post your questions in a new thread.  This thread is 2 years old.

 

Also, you will need a push-enabled application on your BlackBerry that is registered to receive pushes for this to work.

 

Matt