Search code examples
office365exchange-serverexchangewebservices

EWS. UpdateItem. Why doesn't ChangeKey change?


In EWS ItemId tag has ChangeKey attribute. This is what Exchange documentation says about this attribute:

When you work with items in Exchange, another value to keep in mind is the ChangeKey attribute. This value, in addition to the item ID, is used to keep track of the state of an item. Any time an item is changed, a new change key is generated.

So in my app I'm performing UpdateItem operation. This is the XML that I send to the server:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
  <t:RequestServerVersion Version="Exchange2007_SP1" />
</soap:Header>
<soap:Body>
  <m:UpdateItem xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite" SendMeetingInvitationsOrCancellations="SendToNone">
     <m:ItemChanges>
        <t:ItemChange>
           <t:ItemId Id="AAMkADE3MTJkZWNlLTZiYWYtNDY4Yi1hNmM3LWU2MzY2ZDZjYWNhMQBGAAAAAACoXti5FFu8TJNLLS5k9vC8BwAcJDq8WkSCQ77jdOtyazgnAAAAAAEMAAAcJDq8WkSCQ77jdOtyazgnAACOg4SZAAA=" ChangeKey="`CQAAAA==`" />
           <t:Updates>
              <t:SetItemField>
                 <t:FieldURI FieldURI="message:IsRead" />
                 <t:Message>
                    <t:IsRead>false</t:IsRead>
                 </t:Message>
              </t:SetItemField>
           </t:Updates>
        </t:ItemChange>
     </m:ItemChanges>
  </m:UpdateItem>
 </soap:Body>
</soap:Envelope>

Please note that ChangeKey is CQAAAA==. And this is the response that I receive:

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
 <s:Header>
  <h:ServerVersionInfo xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" MajorVersion="15" MinorVersion="0" MajorBuildNumber="1365" MinorBuildNumber="1" Version="V2_23" />
</s:Header>
<s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <m:UpdateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
     <m:ResponseMessages>
        <m:UpdateItemResponseMessage ResponseClass="Success">
           <m:ResponseCode>NoError</m:ResponseCode>
           <m:Items>
              <t:Message>
                 <t:ItemId Id="AAMkADE3MTJkZWNlLTZiYWYtNDY4Yi1hNmM3LWU2MzY2ZDZjYWNhMQBGAAAAAACoXti5FFu8TJNLLS5k9vC8BwAcJDq8WkSCQ77jdOtyazgnAAAAAAEMAAAcJDq8WkSCQ77jdOtyazgnAACOg4SZAAA=" ChangeKey="CQAAAA==" />
              </t:Message>
           </m:Items>
           <m:ConflictResults>
              <t:Count>0</t:Count>
           </m:ConflictResults>
        </m:UpdateItemResponseMessage>
      </m:ResponseMessages>
    </m:UpdateItemResponse>
 </s:Body>
</s:Envelope>

As you can see the returned change key is still CQAAAA==. Why hasn't it changed?


Solution

  • Read/unread status is technically not part of the message itself; it is stored separately. That is how per-user message status is implemented in the PF store. folders.

    If you modify any other property, the change key will change.