Je dois envoyer des notifications push à un périphérique Blackberry à partir de mon application ASP.NET. Quelle est la meilleure façon de le faire? Y a-t-il des bibliothèques .NET? Ai-je besoin de compiler une demande PAP par moi-même ou quelque chose comme ça?Blackberry Push Service Initiator sur IIS/.NET
4
A
Répondre
1
Il existe désormais un SDK C# BlackBerry Push open-source pouvant être utilisé et consommé par une application ASP.NET.
Le projet est hébergé sur CodePlex here.
0
Si vous ne voulez pas mettre en œuvre une bibliothèque 3ème partie, ce code a bien fonctionné pour moi:
private static string UrlForPush = "https://cp815.pushapi.na.blackberry.com";
private static string ApplicationId = "your_appid";
private static string Password = "your_password";
// NOTE: deviceToken below is the BB PIN unique to each device.
public static string SendPushNotification(string deviceToken, string message)
{
try
{
var myPushId = DateTime.Now.ToFileTime().ToString();
var deliverBefore = DateTime.UtcNow.AddMinutes(5).ToString("s", CultureInfo.InvariantCulture) + "Z";
var boundary = "CiTySoUrCeDbLaCkBeRrY";
var url = UrlForPush + "/mss/PD_pushRequest";
var 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\" \"http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd\">");
data.AppendLine("<pap>");
data.AppendLine("<push-message push-id=\"" + myPushId + "\" deliver-before-timestamp=\"" + deliverBefore + "\" source-reference=\"" + ApplicationId + "\">");
data.AppendLine("<address address-value=\"" + deviceToken + "\"/>");
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: " + myPushId);
data.AppendLine("");
data.AppendLine(message);
data.AppendLine("--" + boundary + "--");
data.AppendLine("");
// Create the Request...
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = ("POST");
request.Accept = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
request.Credentials = new NetworkCredential(ApplicationId, Password);
request.PreAuthenticate = true;
request.ContentType = "multipart/related; boundary=" + boundary + "; type=application/xml";
SetBasicAuthHeader(request, ApplicationId, Password);
var bytes = new ASCIIEncoding().GetBytes(data.ToString());
request.ContentLength = bytes.Length;
// Write Stream...
using (var stream = request.GetRequestStream())
{
stream.Write(bytes, 0, bytes.Length);
}
// Get Response ...
var responseAsString = string.Format("Push ID: {0}", myPushId) + Environment.NewLine + Environment.NewLine;
using (var response = request.GetResponse() as HttpWebResponse)
{
var reader = new StreamReader(response.GetResponseStream());
responseAsString += reader.ReadToEnd();
reader.Close();
}
// Return...
return responseAsString;
}
catch (Exception ex)
{
return ex.Message;
}
}
private static void SetBasicAuthHeader(WebRequest webRequest, String userName, String password)
{
var authInfo = userName + ":" + password;
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
webRequest.Headers["Authorization"] = "Basic " + authInfo;
}
Questions connexes
- 1. BlackBerry Simulator & BIS Push Service
- 2. Sample Push Service Code application client: Blackberry
- 3. Comment intégrer Blackberry Push Service depuis .NET
- 4. Notifications Push Blackberry (Notifications locales)
- 5. Tutoriel de notification push Blackberry
- 6. Push d'Apple Notification Service
- 7. Apple Push Notification Service
- 8. Service de notification push BB
- 9. Existe-t-il une documentation pour le protocole PAP utilisé par le Blackberry Push Service?
- 10. BlackBerry Push Service return rc = 10002, qu'est-ce que cela signifie?
- 11. Push d'Apple Service de notification
- 12. android push notification service comparaison
- 13. Push d'Apple Service de notification
- 14. Comment mettre en œuvre un service push pour une application BlackBerry?
- 15. Service de notification push Apple - aucune notification sur l'appareil
- 16. Mise en œuvre de la notification push Blackberry
- 17. Prise en charge de Blackberry Push en Inde
- 18. push service de notification de notification
- 19. Service de rétroaction pour la notification push
- 20. Service de données en itinérance sur les téléphones Blackberry
- 21. HTTP Push sur Heroku
- 22. Messages push sur l'iPhone
- 23. impossible d'obtenir une notification push à l'aide du service de notification push du dirigeable urbain?
- 24. Connexion au service Web depuis BlackBerry
- 25. Notification Service pour l'application Blackberry OS 4.5
- 26. une question relative au service de notification push Apple
- 27. Disponibilité du service de notification Push dans cette situation?
- 28. Comment puis-je tester Apple Push Notification Service sans iPhone?
- 29. Apple Push Notification Service utilisant Urban Airship dans iPhone
- 30. Comment tester le service de notification de notification push iphone