C# BlackBerry Push Service SDK – Part II

The low-level push API code is complete with support added for RIM specific messages.

The next layer (IPapService) which exposes a low-level facade that can send messages and return responses together with a listener that can called by the push service itself is now complete.

Layer three is next. This is a terribly complex layer and contains the majority of the SDK.

Thankfully it is split into manageable segments.

IPushApplicationService and it’s repository has been completed – although additional validation is still required.

IPushCountService and it’s repository has been completed – this was an easy one…

IPushRequestService and IPushRequestDetailService and the associated repositories have been completed.

IPushStatsService and IPushStatsBatchUpdaterService together the the stats repository are fully implemented – a tricky little devil but now implemented according to the SDK documentation.

So far so good – next I tried to write the IPushService code and realised that I really need the subscription service support before it will make sense! So the ISubscriptionService is now being looked at – this is a very wide interface so will take a day or two to write.

Obviously on the way to implementing subscription I will also implement ISubscriptionQueryService needed to talk to the BlackBerry infrastructure however unlike the Java API, I will reuse the PAP service to handle the message routing…

Last up will be acknowledgement support and providing the hooks necessary for SDK users’ to utilise inbound data.

Clearly once this code is done I will be getting a Push Plus experimental key and putting the code through its paces to see if the subscription, acknowledgements and request storage code works as expected – that will be fun…

C# BlackBerry Push Service SDK

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

    Push requests fall into two types:

  1. XML request
  2. 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?

The Problems
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.

Happy coding