5

UPDATE: The plot thickens. I changed my channel name and it is suddenly working (which means it wasn't a problem with my push service, since I'm getting the same HTTP response from the Microsoft Push Notification server).

To me, however, this is not a solution. How will I be able to test this and KNOW my users are getting their push notifications if I'm getting the same response when it's not working as I do when it is?

[ORIGINAL POST]

I've been trying to get push notifications sent to my Windows Phone 7 device, but I'm having very big problems that I can't find any answers for. I'll start with the c# code.

I set up push notifications using the following C# code.

private HttpNotificationChannel channel;
private static string PUSH_CHANNEL = "MySpecialPushChannel";
private Uri PushUri = null;
private bool IsPushRegistered = false;

public void StartPushSubscription()
{
    try
    {
        channel = HttpNotificationChannel.Find(PUSH_CHANNEL);
    }
    catch
    {}

    if (channel != null)
    {            
        PushUri = channel.ChannelUri;
        if (!channel.IsShellTileBound)
            channel.BindToShellTile();
    }
    else
    {
        channel = new HttpNotificationChannel(PUSH_CHANNEL);
        channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(channel_ChannelUriUpdated);
        channel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(channel_HttpNotificationReceived);
        channel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(channel_ErrorOccurred);

        try
        {
            channel.Open();
            channel.BindToShellTile();
        }
        catch (Exception err)
        {
            channel = null;
            IsPushRegistered = false;
            // Code to try again
        }
    }
}

void channel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
    PushUri = e.ChannelUri;
    IsPushRegistered = true;
}

I'm following the standard WP7 push structure:

  1. Find the HttpNotificationChannel (or start a new one)
  2. Register event handler to get the push notification uri back
  3. Open the channel
  4. Bind to the tile
  5. Handle the channel Uri (which we send to our service to await the happy day when we send the push notification

OK... so far so good. No errors, I get my Uri, send it to my service just fine. I pin my app to the start screen and my service sends a push request to the Uri (sending just the count so that I get a little push count number in the upper right hand corner). I get back an HTTP 200 status with the following:

DeviceConnectionStatus => Connected

NotificationStatus => Received

SubscriptionStatus => Active

And then... nothing. No push status shows up on my app. I've now tried it on my device, in the emulator, on another device, and with multiple servers and the result is always the same. Everything looks like it is working except for the fact that it doesn't work.

Eran
  • 387,369
  • 54
  • 702
  • 768
MatthiasS
  • 473
  • 4
  • 11
  • How do you format the notifications that are sent? I'd like to see the XML you are using and the headers. – Den May 12 '11 at 17:46
  • I'm using the PHP WP7 push notifcation system here: http://phpwindowsphonepush.codeplex.com/ But isn't that kind of a moot point? I mean... if I'm getting a success message back from the Microsoft Push Notification Server, doesn't that mean that the push request was successful? Or is there a "you did something wrong, but we're going to give you a success message anyway" version of the response? – MatthiasS May 12 '11 at 18:03
  • Not familiar with PHP, but take a look at a C# implementation here: http://dotnet.dzone.com/articles/sending-tile-push At least when I tried passing an image, if it doesn't conform to the rules (80KB/15 seconds), the status will be Received but the notification will fail. – Den May 12 '11 at 19:01
  • Regarding your post update - You must use Fully Qualified Domain Names with your PN service. – keyboardP May 12 '11 at 19:03
  • kerboardP - I'm not doing a live tile, just a numbered tile update. Those don't require defining the domain in the app. As for the Fully Qualified Domain Name, I didn't change a single character in my service between the time it didn't work and the time it did.
    Dennis - I changed just the push notification channel name and nothing else and it started working. This seems to indicate that my service was fine. Am I right on that count? (I'm not sure... I'm a Silverlight dev not a web services guy)
    – MatthiasS May 12 '11 at 20:17
  • Re your update: the ChannelName needs to be a Unique Name for your application, and ALL other applications. So if you had two test apps that used the same ChannelName you could have issues. Also, right now you're only allowed 15 open channels across ALL applications on the device. So if you have a lot of apps that do notifications, some will get shut down. – Joe McBride May 12 '11 at 20:20

2 Answers2

3

To me, however, this is not a solution. How will I be able to test this and KNOW my users are getting their push notifications if I'm getting the same response when it's not working as I do when it is?

The answer is, you can't. It's a limitation of how WP7 handles notifications.

For structured notifications like Tile and Toast, if you get the Connected/Active/Received/200 response, then you can know that MPNS accepted your notification request. However, this does not mean that you have sent a valid XML payload.

The component that handles parsing XML is the Push Client, the process running on the phone that accepts push notifications and deals them out to appropriate applications, displays the toast, etc.

If you have sent invalid XML, there is absolutely no indication that you've done so. At most, if you try to send the notification again to that same push channel URI, you'll get a 404 in response. Apparently getting an invalid XML payload for a specific application makes that application's push channel close, requiring you to go through the whole procedure again.

I've discovered this while debugging with our server team, and through trying to get the phone to display an alternate live tile. The only advice I can offer you is to quadruple-check your XML.

You will get errors in your error event handler for your push notification channel for Toast notifications that have invalid XML, since you are able to send/receive toast notifications while the application is active.


If anyone from Microsoft is reading this, PLEASE provide more thorough documentation on possible error states in the push notification system. We also need an event handler for Tile notifications, or at least allow us to receive tile notifications while the app is in the foreground and fire the notification channel error event so that we can be aware that our XML payload is invalid.

Especially if your web service isn't built with WCF, .NET, Azure, and whatever, working with Push Notifications on WP7 is like wandering blind.

Documentation for an exception message reading "InvalidOperationException(Failed to open channel)" should not read: "This exception is raised when the notification channel failed to open. Try opening the notification channel again." (reference)

michael.bartnett
  • 787
  • 7
  • 20
0

are you getting the URL from each device? you need to get a URL from the push notification sevice for each device everytime your device connects,

when it does you need to find a way of retrieving the url from each client,

once you do that and your still not receiving push notifications then I would write to microsoft to see if they can see anything to do with the push notifications