ActiveSync Contacts Server

I didn’t get as much time this week to work on my ActiveSync server as I would have liked, but I’m happy to say I have Contacts now syncing. Syncing is a stretch, since it only works one way!

I’ve published the service to Azure, so if you’d like to test it out, you can follow these steps. I’ve tested it against iOS, so I’m not sure how Android or Windows Phone will cope.

IMG_0008Under settings, choose Mail, Contacts, Calendars and press “Add Account”. Select Exchange.IMG_0009Fill any old rubbish into the next screen. I haven’t added AutoDiscovery support, so this step will just fail after a few seconds and you’ll be prompted to enter the details manually.

IMG_0011Enter as the Server. The username and password values don’t matter here either.

Once you hit Next, it will verify the details and you should see blue ticks appear beside the entries. Hit Done.


Unselect Mail, Calendars, Reminders and Notes and hit Save. My ActiveSync server doesn’t support any of these, but it will serve to keep your iPhone from being cluttered with useless folders. Once you hit save, it should sync down the contacts into a folder called “Recruitment Agents” and be populated with the members of the Avengers.


My aim here is to create a directory of recruitment agents, so you’ll know who’s calling and what agency they are from. I think this could grow into an inbox and calendar, so agents email to a dedicated inbox and can create interview appointments for you, that sort of thing.

I also want to support Direct Push, but I’m not 100% sure how to make that work efficiently, so Push it disabled at the moment.

If you do test it out, I’d be grateful for your feedback (works, doesn’t work, etc.). Email me or tweet me.


Beginning ActiveSync Server

In order to occupy my mind whilst I look for a contract role (if you have one, please let me know!), I decided to start digging into ActiveSync and see what would be involved in building a simple server.

As I’m looking for a new role, I get calls from recruitment agents here in the UK and it’s a little hard to keep track of, especially if I’m out and about. Wouldn’t it be nice if I could just add a predefined list of contacts to my phone? That way I’ll always know who’s calling and what agency they are from [Most of the time – some agents block their numbers]. Another benefit is that when I’m done job hunting, I can remove all the contacts by simply removing the settings from my iPhone, instead of clogging up my personal contacts and having to delete them one by one. It also lets me add agencies that haven’t yet called me.

So enough about my “motivations”. I want to document this journey with a little detail, mainly so I have something to refer back to in the coming months. ActiveSync, to give you a little background, is a Microsoft Protocol designed for mobile devices to enable them to sync data with Exchange server. It’s standard across all major mobile platforms and is used by Outlook and other Exchange clients. I always though it was a closed protocol, but I discovered that it’s fully documented and doesn’t need to be licensed anymore!  A quick Google and I found a ZIP containing 132 PDFs, covering the entire spec. I don’t know about you, but this is heaven for me. I love turning specifications into working software!

The starting point was [MS-ASHTTP].pdf , which covers the basics of the HTTP protocol. After implementing the OPTIONS verb in my API, I was able to get the iPhone to add my server. The OPTIONS verb returns basic information about the server, such as its version and the commands it supports. Nothing crazy!


The first issue was the SSL. I had to add the server, let validation fail, save the settings and then disable SSL under Advanced Settings before trying again. Once I had successfully added the server, I turned off all data with the exception of Contacts.


You can see that the “Automatic Reply” setting is “Loading”. I’ve no idea what to return to make that go away, so it’s something I will need to come back to at a future date.

With my iPod successfully connected to my ActiveSync server, I now needed to understand the Commands and the Sync process. This involved reading  [MS-ASCMD].pdf. Not all of it, but just the sections on FolderSync and Sync.  Having grasped the basics of the flow, I ran into a wall named WBXML!

WBXML is a standard for encoding XML to reduce payload size. Created back in the WAP days, it’s still in use. As luck would have it, I wrote a WBXML parser back in 2001 when I worked for CMG, so I knew the principal. Rather than do it again, I copied Microsoft’s sample code 🙂

With a working WXML encoding/decoder, I was in business!  Or so I thought!

I’ll save you my tale of woe and angst, sufficeit to say the WebAPI MediaFormatters caught me out. When ever I returned data to the iPod, I would get a cryptic message in the logs about a code page not being selected. After lots of fiddler and Wiresharking, I realised by perfect WBXML was being converted to JSON by the WebAPI ! I added a new MediaFormatter and, bingo, my contacts folder appeared on my iPod.

IMG_0006It was, of course, empty!


After some more reading, I figured out how to add a Contact!

IMG_0002I celebrated with a macaroon. There is, of course, lots more to do and tracking sync changes is not an easy thing to do, but my aim is simple. I will add a simple web interface and database.  It is then a matter of adding the details of the various recruitment agenicies .

I’ll be blogging again soon I hope!