Reputation: 1384
I'm trying to implement a Push Notification based app on Windows Phone. I have been able to retrieve the Channel Uri on the emulator and send a Push notification to the emulator through my server.
While on the other hand I am facing issues with deploying the same solution on my device. The usage of the Uri returns a NullReferenceException. While the Channel Uri shows "Cannot evaluate expression".
Here's my code placed in the page constructor. I have tried changing the _pushChannelName as well.
private static string _pushChannelName = "TestApp";
// Constructor
public MainPage()
{
HttpNotificationChannel pushChannel;
InitializeComponent();
pushChannel = HttpNotificationChannel.Find(_pushChannelName);
if (pushChannel == null)
{
MessageBox.Show("NULL");
pushChannel = new HttpNotificationChannel(_pushChannelName);
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(pushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(pushChannel_ErrorOccurred);
pushChannel.ShellToastNotificationReceived +=new EventHandler<NotificationEventArgs>(pushChannel_ShellToastNotificationReceived);
pushChannel.Open();
pushChannel.BindToShellToast();
}
else
{
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(pushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(pushChannel_ErrorOccurred);
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(pushChannel_ShellToastNotificationReceived);
//System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
textBox1.Text = pushChannel.ChannelUri.ToString();
}
MessageBox.Show(String.Format("Channel Uri is {0}", pushChannel.ChannelUri.ToString()));
}
I have also tried checking the Uri from the ChangeUri event. The event does not trigger on the device, while Push apps are working fine. Even the channel limit is not met.
private void pushChannel_ChannelUriUpdated(Object sender, NotificationChannelUriEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show(String.Format("Channel Uri is {0}",
e.ChannelUri.ToString()));
});
}
Upvotes: 2
Views: 839
Reputation: 94
Many user have face to this problem. The solutions are two.
The firs solution is to stop all Application, games and others software that connected with marketplace account and remove or stop notifications. Restart Phone (power off/on) and wait 24 hours.
Second solution is to pay to Marketplace and register your application, get certificate from Marketplace and insert to your Application. Then when open new channel must use second overload constructor of static class "HttpNotificationChannel":
[SecuritySafeCritical] public HttpNotificationChannel(string channelName, string serviceName);
Upvotes: 1