Note that there are some explanatory texts on larger screens.

plurals
  1. POC# server side for BlackBerry Push Service
    primarykey
    data
    text
    <p>I am trying to send a Push Message to my BlackBerry App. The BlackBerry successfully receives the message via the <code>php</code> server side code. However I am struggling with the c# server side code for quite sometime now. Following is the code that I am running:</p> <pre><code>string userName = "&lt;appID&gt;"; string userPW = "&lt;password&gt;"; public static void SetBasicAuthHeader(WebRequest req, String userName, String userPassword) { string authInfo = userName + ":" + userPassword; authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); req.Headers["Authorization"] = "Basic " + authInfo; } public static void SetProxy(WebRequest req) { Uri newUri = new Uri("http://cp(AppID).pushapi.eval.blackberry.com"); WebProxy proxy = new WebProxy(); proxy.Address = newUri; proxy.Credentials = new NetworkCredential("&lt;appID&gt;", "&lt;password&gt;"); req.Proxy = proxy; } public bool pushTest(string msg) { HttpWebResponse HttpWRes = null; HttpWebRequest HttpWReq = null; string pin = "xxxxxxxx"; // or actual pin of device string applicationID = "xxxxxxxxxxxxxxxxxxxxxx"; string BOUNDARY = "mPsbVQo0a68eIL3OAxnm"; //string msg1 = "testing c#"; // the message to send string userName = "&lt;appID&gt;"; string userPW = "&lt;password&gt;"; string url = "https://pushapi.eval.blackberry.com/mss/PD_pushRequest"; HttpWReq = (HttpWebRequest)WebRequest.Create(url); SetProxy(HttpWReq); HttpWReq.Method = ("POST"); HttpWReq.Accept = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"; //HttpWReq.Credentials = new NetworkCredential(userName, userPW); HttpWReq.PreAuthenticate = true; HttpWReq.ContentType = "multipart/related; boundary=" + BOUNDARY + "; type=application/xml"; SetBasicAuthHeader(HttpWReq, userName, userPW); StringBuilder dataToSend = new StringBuilder(); dataToSend.AppendLine("--" + BOUNDARY); dataToSend.AppendLine("Content-Type: application/xml; charset=UTF-8"); dataToSend.AppendLine(""); dataToSend.AppendLine("&lt;?xml version=\"1.0\"?&gt;"); dataToSend.AppendLine("&lt;!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP 2.1//EN\" \"http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd\"&gt;"); dataToSend.AppendLine("&lt;pap&gt;"); string myPushId = DateTime.Now.ToFileTime().ToString(); dataToSend.AppendLine("&lt;push-message push-id=\"" + myPushId + "\" source-reference=\"" + applicationID + "\"&gt;"); dataToSend.AppendLine("&lt;address address-value=\"" + pin + "\"/&gt;"); dataToSend.AppendLine("&lt;quality-of-service delivery-method=\"unconfirmed\"/&gt;"); dataToSend.AppendLine("&lt;/push-message&gt;"); dataToSend.AppendLine("&lt;/pap&gt;"); dataToSend.AppendLine("--" + BOUNDARY); dataToSend.AppendLine("Content-Type: text/plain"); dataToSend.AppendLine("Push-Message-ID: " + myPushId); 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(); // MessageBox.show(""+HttpWRes); } catch (Exception ex) { //push failed } if (HttpWRes != null) { HttpWRes.Close(); } return true; } </code></pre> <p>I get the following error:</p> <pre><code>Push failed! System.Net.WebException: Unable to connect to the remote server ---&gt; System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 68.171.224.60:80 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket&amp; socket, IPAddress&amp; address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception&amp; exception) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetRequestStream(TransportContext&amp; context) at System.Net.HttpWebRequest.GetRequestStream() </code></pre> <p>Is there any issue with the credentials applied?or the URL? Please help!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload