【问题标题】:establishing push notification in windows phone 7在 Windows Phone 7 中建立推送通知
【发布时间】:2011-07-06 11:11:53
【问题描述】:

我必须在我的项目中实现推送通知。 它有sender(windows手机窗口应用),wcf服务和客户端(windows手机应用)。

如何替换发件人并使用我的 url 发送和接收来自客户端的通知?

我希望发送者是模拟器本身中的某个应用程序,它与客户端并行运行并将数据连续推送到客户端。

如何开发这样的应用程序

谁能告诉我路。

【问题讨论】:

  • 对不起,我没有理解你的意思。请澄清你的问题。此外,通知是单向的,因此您不能使用它们来“发送和接收来自客户端的通知”
  • 我现在编辑问题你明白了吗?

标签: c# windows-phone-7 push-notification mpns


【解决方案1】:

听起来好像您希望使用两个 WP7 应用程序使用推送通知功能来回发送消息。对吗?

我的理解是,您仍然需要每台设备使用订阅成功时发回的唯一 URI 订阅推送通知服务(MS 托管)。似乎 SL3/4 可以创建 HttpWebRequest 对象,因此应该能够制定一个正确的包来发送,但是,在我看来,困难在于如何获取要将帖子发送到的设备的 URI。通常,帖子会发送给订阅者,订阅者知道它的 on URI,因为它是在订阅阶段返回的。

我的 WCF 托管代码仅在 WCF 知道设备的 URI 时才有效,该设备的 URI 在调用 WCF 方法时发送:

    public bool sendTileUpdate(string tileText, string url, string image)
    {
        string TilePushXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<wp:Notification xmlns:wp=\"WPNotification\">" +
                "<wp:Tile>" +
                "<wp:BackgroundImage>{2}</wp:BackgroundImage>" +
                "<wp:Count>{0}</wp:Count>" +
                "<wp:Title>{1}</wp:Title>" +
                "</wp:Tile>" +
                "</wp:Notification>";

        try
        {
            HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(url);
            sendNotificationRequest.Method = "POST";
            sendNotificationRequest.Headers = new WebHeaderCollection();
            sendNotificationRequest.ContentType = "text/xml";

            // Tile
            sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "token");
            sendNotificationRequest.Headers.Add("X-NotificationClass", "1");

            string str = string.Format(TilePushXML, "", tileText, image);

            byte[] strBytes = new UTF8Encoding().GetBytes(str);
            sendNotificationRequest.ContentLength = strBytes.Length;
            using (Stream requestStream = sendNotificationRequest.GetRequestStream())
            {
                requestStream.Write(strBytes, 0, strBytes.Length);
            }
            HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
            string notificationStatus = response.Headers["X-NotificationStatus"];
            string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];
            return true;
        }
        catch (Exception e)
        {
            return false;
        }
    }

我知道这是一个 TileNotification,但原理是一样的。

我了解 Mango(WP7.1 和 SL4)将支持sockets,这可能是您的设备更合适的通信方式!

祝你好运,

杰森。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-15
    • 2011-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多