Question

I'm currently writing an active sync client and I've successfully managed to do a folder sync. I'm now attempting to sync the "Notes" folder (using the sync command) and it's giving me an error code 4, which Microsoft describes as "Protocol Error" -- I don't see anything wrong in the protocol that I'm sending, here is the sections from my log:

Folder sync RequestBody :

<?xml version="1.0" encoding="utf-8" ?>
<FolderSync xmlns="FolderHierarchy:">
    <SyncKey>0</SyncKey>
</FolderSync>

FolderSync ResponseBody:

<?xml version="1.0" encoding="utf-8" ?>
<FolderSync xmlns="FolderHierarchy:">
    <Status>1</Status>
    <SyncKey>1</SyncKey>
    <Changes>
        <Count>12</Count>
        <Add>
            <ServerId>1</ServerId>
            <ParentId>0</ParentId>
            <DisplayName>Calendar</DisplayName>
            <Type>8</Type>
        </Add>
        <Add>
            <ServerId>2</ServerId>
            <ParentId>0</ParentId>
            <DisplayName>Contacts</DisplayName>
            <Type>9</Type>
        </Add>
        <Add>
            <ServerId>3</ServerId>
            <ParentId>0</ParentId>
            <DisplayName>Deleted Items</DisplayName>
            <Type>4</Type>
        </Add>
        <Add>
            <ServerId>4</ServerId>
            <ParentId>0</ParentId>
            <DisplayName>Drafts</DisplayName>
            <Type>3</Type>
        </Add>
        <Add>
            <ServerId>5</ServerId>
            <ParentId>0</ParentId>
            <DisplayName>Inbox</DisplayName>
            <Type>2</Type>
        </Add>
        <Add>
            <ServerId>6</ServerId>
            <ParentId>0</ParentId>
            <DisplayName>Journal</DisplayName>
            <Type>11</Type>
        </Add>
        <Add>
            <ServerId>7</ServerId>
            <ParentId>0</ParentId>
            <DisplayName>Junk E-Mail</DisplayName>
            <Type>12</Type>
        </Add>
        <Add>
            <ServerId>8</ServerId>
            <ParentId>0</ParentId>
            <DisplayName>Notes</DisplayName>
            <Type>10</Type>
        </Add>
        <Add>
            <ServerId>9</ServerId>
            <ParentId>0</ParentId>
            <DisplayName>Outbox</DisplayName>
            <Type>6</Type>
        </Add>
        <Add>
            <ServerId>10</ServerId>
            <ParentId>0</ParentId>
            <DisplayName>Sent Items</DisplayName>
            <Type>5</Type>
        </Add>
        <Add>
            <ServerId>11</ServerId>
            <ParentId>0</ParentId>
            <DisplayName>Tasks</DisplayName>
            <Type>7</Type>
        </Add>
        <Add>
            <ServerId>RI</ServerId>
            <ParentId>0</ParentId>
            <DisplayName>RecipientInfo</DisplayName>
            <Type>19</Type>
        </Add>
    </Changes>
</FolderSync>

My Sync RequestBody :

<?xml version="1.0" encoding="utf-8" ?>
<Sync xmlns="AirSync:">
    <Collections>
        <Collection>
            <SyncKey>0</SyncKey>
            <CollectionId>8</CollectionId>
            <DeletesAsMoves>1</DeletesAsMoves>
            <GetChanges/>
        </Collection>
    </Collections>
</Sync>

Lists this exception:

SyncCommand_OnExecute_Exception : 
Microsoft.Exchange.AirSync.AirSyncPermanentException
   at Microsoft.Exchange.AirSync.SyncCommand.ParseSyncKey(SyncCollection collection)
   at Microsoft.Exchange.AirSync.SyncCommand.SyncTheCollection(SyncCollection collection, Boolean createSubscription, Boolean tryNullSync)
   at Microsoft.Exchange.AirSync.SyncCommand.OnExecute()

And provides the following ResponseBody :

<?xml version="1.0" encoding="utf-8" ?>
<Sync xmlns="AirSync:">
    <Status>4</Status>
</Sync>

Any ideas why it is failing there? This is the first sync of the folder, so the SyncKey SHOULD be 0...

Was it helpful?

Solution

From http://msdn.microsoft.com/en-us/library/gg675447(v=exchg.80).aspx :

A Status element (section 2.2.3.162.16) value of 4 is returned if the GetChanges element is present and empty or set to 1 (TRUE) when the SyncKey element value is 0 (zero). No error is returned if the GetChanges element is absent or set to 0 (FALSE) when the SyncKey value is 0 (zero).

You have present and empty in your xml.

You only may set GetChanges to 1 or live it empty (which is by default = 1) in any consequential sync request, not in initial sync request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top