Search code examples
javapush-notificationwindows-phone-8.1mpns

MPNS bad request when push notification (WP 8.1)


I'm currently developping an mobile application based on Cordova (version 4.0.0) for Windows Phone 8.1.

I implemented the Java code from API Java-MPNS (from github of notnoop) to send notification to my device.

When I push the notification message to MPNS, I get this error :

HTTP/1.1 400 Bad Request [Content-Length: 0, X-WNS-MSG-ID: 50267BB8627BC17D, X-WNS-DEBUG-TRACE: DB5SCH101121935, Strict-Transport-Security: max-age=31536000; includeSubDomains, WWW-Authenticate: Bearer, Date: Thu, 07 Jan 2016 09:13:01 GMT] org.apache.http.conn.BasicManagedEntity@1ab5b13

From document of Push Notification Service response codes for Windows Phone 8, this error code means that XML document or notification URI is malformed.

Here's my notification URI :

https://db5.notify.windows.com/?token=AwYAAAC%2fHaOBh3zOgFjUbZuCSMgzXY29aQDT9wKfpkiPsd85WKBA8muqx4is4r1nBVXQOtRKqe5cc%2fxat7hq6sZBruvm6nQF7p9Sl71TIiqnGvlrdDDw6v0anax4bXUCtflPwEc%3d

Here's the XML document (generated by Java-MPNS from Java class TileNotification):

<?xml version="1.0" encoding="utf-8"?>
    <wp:Notification xmlns:wp="WPNotification">
        <wp:Tile>
            <wp:Count>1</wp:Count>
            <wp:Title>Demo App Windows</wp:Title>
            <wp:BackContent>New notification</wp:BackContent>
        </wp:Tile>
    </wp:Notification>

When I compare this XML document and XML document from documentation of How to send and receive Tile notifications for Windows Phone 8, I don't see any difference or error. About my notification URI, I think the link is correct.

But, what is the difference between http://db3.notify.live.net and https://db5.notify.windows.com ?

Is there anyone who already use this API ? Do you have an idea about how to fix it ?


Solution

  • *.notify.live.net is an MPNS channel URI, whereas *.notify.windows.com is a WNS channel URI. You're getting a WNS channel URI (AKA your app is set up to use WNS), but you're trying to use MPNS. The 400 is because WNS expects you to authenticate using OAuth.

    I would double-check if you really want to use MPNS instead of WNS for a new app. MPNS is considered legacy at this point. If you'll want to port your app to Windows build a UWP at some point, you'll need to switch to WNS. More details/guidance can be found here: https://msdn.microsoft.com/en-us/library/windows/apps/dn642085(v=vs.105).aspx

    If you do need to use MPNS, make sure you are using the MPNS APIs to request your channel: https://msdn.microsoft.com/en-us/library/windows/apps/microsoft.phone.notification(v=vs.105).aspx, not the WNS APIs: https://msdn.microsoft.com/en-us/library/windows/apps/hh465412.aspx.