2

Helo,我想问你,我是否可以使用 WCF 服务将磁贴通知从一部手机发送到另一部手机,反之亦然?谢谢

4

1 回答 1

2

要将推送发送到其他手机,您必须拥有 ChannelURI。有关于它的好文章 http://msdn.microsoft.com/en-us/library/hh221549.aspx

当你有这个地址时,你必须发送特殊的 XML 数据

        string textTitle = tbxTitle.Text;
        string textSubtitle = tbxSubtitle.Text;

        string deviceUri = tbxUri.Text;

        string msg =
            "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
            "<wp:Notification xmlns:wp=\"WPNotification\">" +
                "<wp:Toast>" +
                "<wp:Text1>" + textTitle + "</wp:Text1>" +
                "<wp:Text2>" + textSubtitle + "</wp:Text2>" +
                "</wp:Toast>" +
            "</wp:Notification>";

        byte[] msgBytes = new UTF8Encoding().GetBytes(msg);

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(channelUri);
        request.Method = WebRequestMethods.Http.Post;
        request.ContentType = "text/xml";
        request.ContentLength = msg.Length;
        request.Headers["X-MessageID"] = Guid.NewGuid().ToString();
        request.Headers["X-WindowsPhone-Target"] = "toast";
        request.Headers["X-NotificationClass"] = "2";

        Stream requestStream = request.GetRequestStream();
        requestStream.Write(msgBytes, 0, msgBytes.Length);
        requestStream.Close();
于 2013-03-21T15:17:58.953 回答