다음을 통해 공유


How to convert Exchange Item’s EntryID to EWS unique ItemId via EWS Managed API ConvertId call?

One of my customer requested for some guidance for How to convert Exchange Item’s EntryID to EWS unique ItemId via EWS Managed API’s ConvertId call?

Here is the sample code snippet for converting Exchange Item’s EntryID to EWS unique ItemId via Exchange Web Services Managed API’s ConvertId call:

/*NOTE: Following programming examples is for illustration only, without warranty either expressed or implied,
including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose.
This sample code assumes that you are familiar with the programming language being demonstrated and the
tools used to create and debug procedures. This sample code is provided for the purpose of illustration only
and is not intended to be used in a production environment.*/

 //Call the GetConvertedEWSID to convert Item’s EntryID to EWSID 
String sEntryID = "AAAAN0ybz+zO+JOhV4pGimkcYQHAAtH+9AAFtlUAAA==";
String sEWSID = GetConvertedEWSID(service,sEntryID, "TestEx2010@BrijEx2010.com");
MessageBox.Show(sEWSID);
       
//Pass ExchaneService, ItemEntryID and SMTP address of parent Mailbox of Item as Parameters
private String GetConvertedEWSID(ExchangeService esb,String sID,String strSMTPAdd)
{
            // Create a request to convert identifiers.
            AlternateId objAltID = new AlternateId();
            objAltID.Format = IdFormat.EntryId;
            objAltID.Mailbox = strSMTPAdd;
            objAltID.UniqueId = sID;

            //Convert PR_ENTRYID identifier format to an EWS identifier.
            AlternateIdBase objAltIDBase = esb.ConvertId(objAltID , IdFormat.EwsId);
            AlternateId objAltIDResp = (AlternateId)objAltIDBase;
            return objAltIDResp.UniqueId;
}

Here is EWS SOAP Request and Response for the ConvertId call:

 

EwsRequest --- <EwsLogEntry EntryKind="EwsRequest" ThreadId="8" Timestamp="9/10/2010 4:26:22 AM">
  <?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
      <t:RequestServerVersion Version="Exchange2010" />
    </soap:Header>
    <soap:Body>
      <m:ConvertId DestinationFormat="EwsId">
        <m:SourceIds>
          <t:AlternateId Format="EntryId" Id="AAAAN0ybz+zO+JOhV4pGimkcYQHAAtH+9AAFtlUAAA=="   Mailbox="TestEx2010@BrijEx2010.com" />
        </m:SourceIds>
      </m:ConvertId>
    </soap:Body>
  </soap:Envelope>
</EwsLogEntry>

EwsResponseHttpHeaders --- <EwsLogEntry EntryKind="EwsResponseHttpHeaders" ThreadId="8" Timestamp="9/10/2010 4:26:32 AM">200 OK
Transfer-Encoding: chunked
Content-Encoding: gzip
Vary: Accept-Encoding
X-EwsPerformanceData: RpcC=0;RpcL=0;LdapC=0;LdapL=0;
Persistent-Auth: true
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Date: Thu, 09 Sep 2010 22:56:32 GMT
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET

</EwsLogEntry>

EwsResponse --- <EwsLogEntry EntryKind="EwsResponse" ThreadId="8" Timestamp="9/10/2010 4:26:32 AM">
  <?xml version="1.0" encoding="utf-8"?>
  <s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
      <h:ServerVersionInfo MajorVersion="14" MinorVersion="0" MajorBuildNumber="639" MinorBuildNumber="21" Version="Exchange2010" xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types" xmlns="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="https://www.w3.org/2001/XMLSchema" />
    </s:Header>
    <s:Body xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="https://www.w3.org/2001/XMLSchema">
      <m:ConvertIdResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
        <m:ResponseMessages>
          <m:ConvertIdResponseMessage ResponseClass="Success">
            <m:ResponseCode>NoError</m:ResponseCode>
            <m:AlternateId xsi:type="t:AlternateIdType" Format="EwsId" Id="AAMkADM0MDhiYjI5LTY1YjktNGNjOS04ZjdmLWZhZTlmNzdiNjllOQBGAAAAAADdMVg7cuSIleOBbZVAAA=" Mailbox="TestEx2010@brijex2010.com" />
          </m:ConvertIdResponseMessage>
        </m:ResponseMessages>
      </m:ConvertIdResponse>
    </s:Body>
  </s:Envelope>
</EwsLogEntry>

 

For reference:

Comments

  • Anonymous
    October 21, 2010
    The implication of this exercize is that EntryID always converts to the same value and that it is a reversable process. Today I was watching my push notification listener get different ItemIDs for the same Exchange Calendar item (appointment). How is that possible?I expected two different itemIDs since there was an appointment for the organizer and one for the required attendee, but the ItemID pushed did not match either of the appointments previous ItemIDs and yet GetItem returned an appropriate appointment.How can this be?
  • Anonymous
    November 12, 2010
    Hi Doug, I'm by no means an expert, but previous experience developing a MAPI solution for integrating with Exchange led me to read that PR_SOURCE_KEY is actually the permanent ID field used to identify messages, and PR_ENTRYID is actually susceptible to change for what reasons I have no idea. Maybe Brijs can comment?Dave--Trindaz on Fedang #EWS
  • Anonymous
    April 17, 2011
    EntryId changes when you move appointment, message etc. to another folder.