2013-08-28 53 views
0

我送兩個推通知的麪包和瓷磚(只是一個計數)瓷磚通知 - 無效的XML有效載荷 -

敬酒被接受:

<?xml version="1.0" encoding="UTF-8"?><wp:Notification xmlns:wp="WPNotification"><wp:Toast><wp:Text1></wp:Text1><wp:Text2>asdf</wp:Text2><wp:Param></wp:Param></wp:Toast></wp:Notification> 

瓷磚不會:

<?xml version="1.0" encoding="UTF-8"?><wp:Notification xmlns:wp="WPNotification"><wp:Tile><wp:BackgroundImage></wp:BackgroundImage><wp:Count>122</wp:Count><wp:Title></wp:Title><wp:BackBackgroundImage></wp:BackBackgroundImage><wp:BackTitle></wp:BackTitle><wp:BackContent></wp:BackContent></wp:Tile></wp:Notification> 

這是我提供的xml,我不斷收到格式錯誤。格式有問題嗎?

+0

什麼是目標設備的操作系統版本?一些功能只能從7.5版本 – Eran

+0

Windows Phone 8.0 –

回答

1

平鋪格式應該像

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

發送瓷磚通知code.It會爲我工作。如果有任何疑問,請告知我

protected void ButtonSendTile_Click(object sender, EventArgs e) 
     { 
      try 
      { 
       // Get the Uri that the Microsoft Push Notification Service returns to the Push Client when creating a notification channel. 
       // Normally, a web service would listen for Uri's coming from the web client and maintain a list of Uri's to send 
       // notifications out to. 
       string subscriptionUri = TextBoxUri.Text.ToString(); 


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

       // We will create a HTTPWebRequest that posts the tile notification to the Microsoft Push Notification Service. 
       // HTTP POST is the only allowed method to send the notification. 
       sendNotificationRequest.Method = "POST"; 

       // The optional custom header X-MessageID uniquely identifies a notification message. 
       // If it is present, the // same value is returned in the notification response. It must be a string that contains a UUID. 
       // sendNotificationRequest.Headers.Add("X-MessageID", "<UUID>"); 

       // 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>"; 


       // Sets the notification payload to send. 
       byte[] notificationMessage = Encoding.Default.GetBytes(tileMessage); 

       // Sets the web request content length. 
       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); 
       } 

       // Send the notification and get the response. 
       HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse(); 
       string notificationStatus = response.Headers["X-NotificationStatus"]; 
       string notificationChannelStatus = response.Headers["X-SubscriptionStatus"]; 
       string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"]; 

       // Display the response from the Microsoft Push Notification Service. 
       // Normally, error handling code would be here. In the real world, because data connections are not always available, 
       // notifications may need to be throttled back if the device cannot be reached. 
       TextBoxResponse.Text = notificationStatus + " | " + deviceConnectionStatus + " | " + notificationChannelStatus; 
      } 
      catch (Exception ex) 
      { 
       TextBoxResponse.Text = "Exception caught sending update: " + ex.ToString(); 
      } 

     } 
+0

@Bran Gi:只是複製和過去在此代碼中您的發送磁貼按鈕單擊 – MansinhDodiya

+0

做了完全相同的,但我的背景圖像沒有顯示。有什麼需要注意的嗎? – LZH

+0

@LHZ:你在背景圖像參數上傳遞了什麼? – MansinhDodiya