2013-07-10 56 views
2

我從MSDN下載了一個示例,將雲通知發送到Windows Phone 8. 但我總是將頻道URI設置爲空? 我在仿真器8上運行它。推送通知Windows Phone 8來自MSDN的示例

任何想法?

public MainPage() 
    { 
     /// Holds the push channel that is created or found. 
     HttpNotificationChannel pushChannel; 

     // The name of our push channel. 
     string channelName = "ToastSampleChannel"; 

     InitializeComponent(); 

     // Try to find the push channel. 
     pushChannel = HttpNotificationChannel.Find(channelName); 

     // If the channel was not found, then create a new connection to the push service. 
     if (pushChannel == null) 
     { 
      pushChannel = new HttpNotificationChannel(channelName); 

      // Register for all the events before attempting to open the channel. 
      pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated); 
      pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred); 

      // Register for this notification only if you need to receive the notifications while your application is running. 
      pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived); 

      pushChannel.Open(); 

      // Bind this new channel for toast events. 
      pushChannel.BindToShellToast(); 

     } 
     else 
     { 
      // The channel was already open, so just register for all the events. 
      pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated); 
      pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred); 

      // Register for this notification only if you need to receive the notifications while your application is running. 
      pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived); 

      // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.enter code here 
      System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString()); 
      MessageBox.Show(String.Format("Channel Uri is {0}", 
       pushChannel.ChannelUri.ToString())); 

     } 
    } 

在上面的代碼我總是越來越開放的通道爲「空」

+0

有些代碼會有所幫助。 –

+0

請參考上面的代碼 – CodeR

回答

0

,因爲你使用模擬器,所以它永遠是空,嘗試本地機器。

+0

我試過使用一個設備,它仍然是空的,你能解釋一下這個問題是什麼。我也試過它在與互聯網接入的解鎖手機..當我第一次運行應用程序時,它不會崩潰當我第二次運行它崩潰,因爲通道URI爲空 – CodeR

+0

也許這將有助於http://go4answers.webhost4life。 com/Example/push-notification-channel-uri-null-57261.aspx – Grievoushead

+1

感謝您的鏈接,但我已經嘗試過,沒有運氣。我們是否必須將此應用關聯到商店?或者我們需要某種類型的證書來查詢服務器? – CodeR

0

所以問題出在我的網絡環境。 當我在非域名PC上試用它時,它工作正常。感謝您的意見和時間

+0

你好CodeR,你可以請分享適當的解決方案,我也面臨同樣的問題,我嘗試在WP8設備(諾基亞Lumia 520),但通道uri總是NULL。感染我的手機設備有網絡連接以及數據連接。 – WmDev

+0

您是否在域PC上? – CodeR

+0

檢查防火牆設置 – CodeR