C# listener应用程序我刚刚输入了代码“bindtoshelltoast”和“bindtoshelltile”。但谢谢,是的,你的方式是正确的,我只是有其他需要与此应用程序!谢谢您确定此示例同时发送toast和tile吗?这对我不起作用。另外,头文件中的

C# listener应用程序我刚刚输入了代码“bindtoshelltoast”和“bindtoshelltile”。但谢谢,是的,你的方式是正确的,我只是有其他需要与此应用程序!谢谢您确定此示例同时发送toast和tile吗?这对我不起作用。另外,头文件中的,c#,push-notification,windows-phone-8,mpns,C#,Push Notification,Windows Phone 8,Mpns,listener应用程序我刚刚输入了代码“bindtoshelltoast”和“bindtoshelltile”。但谢谢,是的,你的方式是正确的,我只是有其他需要与此应用程序!谢谢您确定此示例同时发送toast和tile吗?这对我不起作用。另外,头文件中的NotificationClass对于每种类型都有一个特定的值,1表示它的磁贴?我不确定您是否可以将这两条消息合并到一个数据包中。即使如此,您的XML仍然无效,因为它缺少结束标记 public MainPage() {


listener应用程序我刚刚输入了代码“bindtoshelltoast”和“bindtoshelltile”。但谢谢,是的,你的方式是正确的,我只是有其他需要与此应用程序!谢谢您确定此示例同时发送toast和tile吗?这对我不起作用。另外,头文件中的NotificationClass对于每种类型都有一个特定的值,1表示它的磁贴?我不确定您是否可以将这两条消息合并到一个数据包中。即使如此,您的XML仍然无效,因为它缺少结束标记
public MainPage()
    {

        HttpNotificationChannel pushChannel;
        string channelName = "TileSampleChannel";
        InitializeComponent();

        pushChannel = HttpNotificationChannel.Find(channelName);

        if (pushChannel == null)
        {
            pushChannel = new HttpNotificationChannel(channelName);

            pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
            pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);

            pushChannel.Open();
            pushChannel.BindToShellTile();


        }
        else
        {
            pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
            pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);

            System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
            MessageBox.Show(String.Format("Channel Uri is {0}",
                pushChannel.ChannelUri.ToString()));

        }
    }


    void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
    {

        Dispatcher.BeginInvoke(() =>
        {
            System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());

            //MessageBox.Show(String.Format("Channel Uri is {0}",
            //    e.ChannelUri.ToString()));

        });
    }

    void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
    {
        Dispatcher.BeginInvoke(() =>
            MessageBox.Show(String.Format("A push notification {0} error occurred.  {1} ({2}) {3}",
                e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData))
                );
    }

}
protected void ButtonSendTile_Click(object sender, EventArgs e)
    {


        try
        {
            string NotifyURI = TextBoxUri.Text.ToString();


            HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(NotifyURI);

            sendNotificationRequest.Method = "POST";


            //Create the toast message

            string notificationData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
            "<wp:Notification xmlns:wp=\"WPNotification\">" +
            "<wp:Toast>" +
            "<wp:Text1>WP8 TOAST</wp:Text1>" +
            "<wp:Text2>" + TextBoxBackContent.Text + "</wp:Text2>" +
            "</wp:Toast>" +
            "</wp:Notification>";

            // Create the tile message.
            string tileMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
            "<wp:Notification xmlns:wp=\"WPNotification\">" +
                "<wp:Tile>" +
                  "<wp:BackgroundImage>" + TextBoxBackgroundImage.Text + "</wp:BackgroundImage>" +
                  "<wp:Count>" + TextBoxCount.Text + "</wp:Count>" +
                  "<wp:Title>" + TextBoxTitle.Text + "</wp:Title>" +
                  "<wp:BackBackgroundImage>" + TextBoxBackBackgroundImage.Text + "</wp:BackBackgroundImage>" +
                  "<wp:BackTitle>" + TextBoxBackTitle.Text + "</wp:BackTitle>" +
                  "<wp:BackContent>" + TextBoxBackContent.Text + "</wp:BackContent>" +
               "</wp:Tile> " +
            "</wp:Notification>";

            byte[] notificationMessage = Encoding.Default.GetBytes(tileMessage);


            sendNotificationRequest.ContentLength = notificationMessage.Length;
            sendNotificationRequest.ContentType = "text/xml";
            sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "token");
            sendNotificationRequest.Headers.Add("X-NotificationClass", "1");


            using (Stream requestStream = sendNotificationRequest.GetRequestStream())
            {
                requestStream.Write(notificationMessage, 0, notificationMessage.Length);
            }


            HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
            string notificationStatus = response.Headers["X-NotificationStatus"];
            string notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
            string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];


            TextBoxResponse.Text = notificationStatus + " | " + deviceConnectionStatus + " | " + notificationChannelStatus;
        }
        catch (Exception ex)
        {
            TextBoxResponse.Text = "Exception caught sending update: " + ex.ToString();
        }

    }
string notificationData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<wp:Notification xmlns:wp=\"WPNotification\">" +
        "<wp:Toast>" +
        "<wp:Text1>WP8 TOAST</wp:Text1>" +
        "<wp:Text2>" + TextBoxBackContent.Text + "</wp:Text2>" +
        "</wp:Toast>" +
        "<wp:Notification xmlns:wp=\"WPNotification\">" +
            "<wp:Tile>" +
              "<wp:BackgroundImage>" + TextBoxBackgroundImage.Text + "</wp:BackgroundImage>" +
              "<wp:Count>" + TextBoxCount.Text + "</wp:Count>" +
              "<wp:Title>" + TextBoxTitle.Text + "</wp:Title>" +
              "<wp:BackBackgroundImage>" + TextBoxBackBackgroundImage.Text + "</wp:BackBackgroundImage>" +
              "<wp:BackTitle>" + TextBoxBackTitle.Text + "</wp:BackTitle>" +
              "<wp:BackContent>" + TextBoxBackContent.Text + "</wp:BackContent>" +
           "</wp:Tile> " +
        "</wp:Notification>";