So among the many aspects of my day-job I’ve been looking into how mobile devices can be integrated into my mega .NET application – a giant line-of-business client/server monster.
Since I recently bought a BlackBerry this device will be integrated first. Now the BB supports a push mechanism which allows me to send data to a BB application in a way that doesn’t require client-side polling.
This sounds pretty neat – it could be used to notify tech support of server problems or notify a customer of a change in their order.
The only problem is the fact that the current API is written in Java by RIM and my application is not – it’s a C# piece of beauty… Still with me?
All this preamble is the sauce for the meat of this post – namely I want to write a native C# API that supports all the features of the RIM Java API.
Looking at the documentation the API is split into two tiers. The first tier manages the communication with the push service. The higher level tier builds upon this low-level tier providing subscriptions, persistent messaging, acknowledgements and full cancellation support.
Last week I started on the low-level tier. This tier is basically concerned with marshalling and unmarshalling messages sent to and received from the Push Service Gateway.
The gateway is a HTTPS web-server that accepts messages posted to the request URI.
- Push requests fall into two types:
- XML request
- XML request and payload in a multipart MIME package
As I’ve found out, the documentation is rather terse and worse the request parser is very strict on the format of the mime package and gives cryptic errors when it throws up.
Sounds like fun eh?
In no particular order – here is a list of issues I found while getting my low-level API to work…
1. HttpWebRequest – obviously I use this object to handle HTTP requests – do not use the Credentials property to set your username and password. It doesn’t work. The API gives instructions on how to setup the Authorization header – follow them!
2. When building the multi-part MIME content make sure there isn’t a blank line between the end of the message XML and the boundary (that took a while to find)
3. The URL given in the email from RIM specifies the address of the gateway – this is a base URL – you will need to add a suffix before you have the actual address necessary the suffix is “mms/PD_pushRequest” without quotes…
4. The SourceReference for a push message is your RIM provided application ID.
After all that I had to get the message response parsed – thankfully this is relatively easy – it’s just XML so I can use a standard object model decorated with XML serialisation attributes.
Some gotchas – the date format requires a custom string for parsing and so the containing class must derive from IXmlSerializable and do things long hand…
So far so good – I’ve finally sent my first push message successfully! The rest of the low-level tier will roll along now.
When it’s in a happy state – I’ll upload it to CodePlex as a open source API.