使用C#作为服务器端的黑莓推送通知 [英] Blackberry Push notification using C# as server side

查看:124
本文介绍了使用C#作为服务器端的黑莓推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 我想用C#网络发送推送通知的黑莓
    服务,但我面临的问题是,它返回异常远程
    服务器返回错误:(404)未找到所有的信息是为正确。
    每RIM标准,所以请帮助我尽快。

      [的WebMethod]
    公共BOOL推(字符串通知)
    {
        BOOL成功= TRUE;
        字节[]字节= Encoding.ASCII.GetBytes(你好);    流requestStream = NULL;
        HttpWebResponse HttpWRes = NULL;
        HttpWebRequest的HttpWReq = NULL;
        串BESName =CP **** pushapi.eval.blackberry.com;
        尝试
        {
            //http://<BESName>:<BESPort>/push?DESTINATTION=<PIN/EMAIL>&PORT=<PushPort>&REQUESTURI=/
            //构建URL来定义我们的BES连接。
            字符串httpURL =htt​​ps://开头+ BESName +?/推DESTINATION = 2B838E45&安培; PORT = 32721&安培; REQUESTURI = /;        //进行连接
            HttpWReq =(HttpWebRequest的)WebRequest.Create(httpURL);
            HttpWReq.Method =(POST);
            //添加nessecary的推头
            HttpWReq.Co​​ntentType =text / plain的;
            HttpWReq.Co​​ntentLength = bytes.Length;
            // *******测试此*******
            HttpWReq.Headers.Add(X-轮缘推ID,2B838E45+〜+ DateTime.Now); //〜+ pushedMessage +
            HttpWReq.Headers.Add(X-环 - 推可靠性,应用程序 - preferred);
            HttpWReq.Headers.Add(X-轮缘推NotifyURL(HTTP://+ BESName +2B838E45〜你好〜+ DateTime.Now).Replace(,));        // ********
            HttpWReq.Credentials =新的NetworkCredential(用户名,密码);        requestStream = HttpWReq.GetRequestStream();
            //写从源数据
            requestStream.Write(字节,0,bytes.Length);        //得到响应
            HttpWRes =(HttpWebResponse)HttpWReq.GetResponse();        VAR pushStatus = HttpWRes.Headers [X-RIM-推状态];        //如果MDS正确地接收到推送参数,它要么用好或接受响应
            如果(HttpWRes.Status code ==的HTTPStatus code.OK || HttpWRes.Status code ==的HTTPStatus code.Accepted)
            {
                成功= TRUE;
            }
            其他
            {
                成功= FALSE;
            }
            //关闭流        HttpWRes.Close();
            requestStream.Close();
        }
        赶上(System.Exception的)
        {
            成功= FALSE;
        }    返回成功;
    }



解决方案

我得到了同样的错误,当我尝试了上述的code。替换

 字符串BESName =CP **** pushapi.eval.blackberry.com

通过

 字符串BESName =cpxxx.pushapi.eval.blackberry.com/mss/PD_pushRequest;

,并确保您在这里提供正确的用户名和密码:

  HttpWReq.Credentials =新的NetworkCredential(用户名,密码);

我的成功= TRUE;

不过,即使上述code成功执行,我还没有看到BlackBerry设备上推送消息。

  1. I am trying to send push notification in blackberry by using C# Web service but i am facing problem is it return exception "The remote server returned an error: (404) Not Found.". all info is correct as per RIM Standard so please Help me ASAP.

     [WebMethod]
    public bool push(string notification)
    {
        bool success = true;
        byte[] bytes = Encoding.ASCII.GetBytes("Hello");
    
        Stream requestStream = null;
        HttpWebResponse HttpWRes = null;
        HttpWebRequest HttpWReq = null;
    
    
        String BESName = "cp****.pushapi.eval.blackberry.com";
        try
        {
            //http://<BESName>:<BESPort>/push?DESTINATTION=<PIN/EMAIL>&PORT=<PushPort>&REQUESTURI=/
            // Build the URL to define our connection to the BES.
            string httpURL = "https://" + BESName +  "/push?DESTINATION=2B838E45&PORT=32721&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", "2B838E45" + "~" + DateTime.Now); //"~" +pushedMessage +
            HttpWReq.Headers.Add("X-Rim-Push-Reliability", "application-preferred");
            HttpWReq.Headers.Add("X-Rim-Push-NotifyURL", ("http://" + BESName + "2B838E45~Hello~" + DateTime.Now).Replace(" ", ""));
    
            // *************************
            HttpWReq.Credentials = new NetworkCredential("Username", "Password");
    
            requestStream = HttpWReq.GetRequestStream();
            //Write the data from the source
            requestStream.Write(bytes, 0, bytes.Length);
    
            //get the response
            HttpWRes = (HttpWebResponse)HttpWReq.GetResponse();
    
            var pushStatus = HttpWRes.Headers["X-RIM-Push-Status"];
    
            //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)
        {
            success = false;
        }
    
        return success;
    }
    

解决方案

I got the same error when I tried your code above. Replace

String BESName = "cp****.pushapi.eval.blackberry.com";

With

String BESName = "cpxxx.pushapi.eval.blackberry.com/mss/PD_pushRequest";

and make sure you provide the right username and password here:

HttpWReq.Credentials = new NetworkCredential("username", "password");

I got success = true;

However, even though the above code executed successfully, I still do not see the push message on the BlackBerry device.

这篇关于使用C#作为服务器端的黑莓推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆