在 Windows Phone 7 中建立推送通知

发布于 2024-11-18 11:36:06 字数 210 浏览 3 评论 0原文

我必须在我的项目中实现推送通知。 它有发送方(Windows Phone 窗口应用程序)、WCF 服务和客户端(Windows Phone 应用程序)。

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

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

如何开发这样的应用程序。

任何人都可以告诉

i have to implement push notification in my project.
It has sender(windows phone window application),wcf service and client(windows phone applcation).

How can i replace the sender and use my url to send and recieve notification from client?

i want sender to be some application in emulator itself that run parallely with the client and push data continously to the client.

how to develop such application

can anyone tell the way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

停顿的约定 2024-11-25 11:36:06

听起来好像您正在寻找使用两个 WP7 应用程序通过推送通知功能来相互发送消息。这是正确的吗?

据我了解,您仍然需要每个设备使用订阅成功时发回的唯一 URI 来订阅推送通知服务(MS 托管)。看起来 SL3/4 可以创建 HttpWebRequest 对象,因此应该能够制定正确的包来发送,但是,我认为困难在于如何获取要将帖子发送到的设备的 URI。通常情况下,帖子会发送给订阅者,订阅者知道其在 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)将支持套接字 这可能是您的设备进行通信的更合适的方式!

祝你好运,

杰森。

It sounds as though you are looking to use two WP7 apps to send messages back and forth to one another using the push notification functionality. Is that correct?

My understanding it that you will still require a each device to subscribe to a push notification service (MS hosted) using the unique URI sent back when the subscription is successful. It appears that SL3/4 can create HttpWebRequest objects and therefore should be able to formulate a correct package to send, however, the difficulty as I see it will be how to obtain the URI of the device you want to send the post to. Normally the post is sent to the subscriber, which knows its on URI as it was returned during the subscribing phase.

My WCF hosted code only works if the WCF knows the URI of the device, which is sent when the WCF method is called:

    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;
        }
    }

I know this is a TileNotification, but the principles are the same.

I understand that Mango (WP7.1 & SL4) will support sockets and this might be a more appropriate way for your devices to communicate!

Good luck,

Jason.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文