Converting Identifiers (Exchange Web Services)

Topic Last Modified: 2008-06-23

Starting with Microsoft Exchange Server 2007 Service Pack 1 (SP1), you can use Exchange Web Services to convert identifiers to other identifier formats that are exposed by Exchange 2007. This is important because the Exchange Web Services identifier format changed between the initial release version of Exchange 2007 and Exchange 2007 SP1. You can use the ConvertId operation to convert between the following identifier formats:

  1. The initial release version of Exchange 2007 Exchange Web Services identifier format. This is represented by the EwsLegacyId enumeration value in IdFormatType.
  2. The Exchange 2007 SP1 Exchange Web Services identifier. This is represented by the EwsId enumeration value in IdFormatType.
  3. The MAPI identifier, as in the PR_ENTRYID property. This is represented by the EntryId enumeration value in IdFormatType.
  4. The availability calendar event identifier. This is a hexadecimal-encoded representation of the PR_ENTRYID property. This is represented by the HexEntryId enumeration value in IdFormatType.
  5. The Exchange store identifier. This is represented by the StoreId enumeration value in IdFormatType.
  6. The Outlook Web Access identifier. This is represented by the OwaId enumeration value in IdFormatType. Passing URLs that are created from this identifier to Outlook Web Access is not supported.

Important

Make sure that the RequestServerVersion SOAP header is set for all Exchange 2007 SP1 requests.

Note

The ConvertId operation validates that a given SMTP address has a valid format. The ConvertId operation does not check to determine whether an SMTP address represents a valid mailbox.

Example

The following code example shows you how to convert from an Outlook Web Access identifier to a PR_ENTRYID identifier. For information about how to set the RequestServerVersion SOAP header on the ExchangeServiceBinding object, see Versioning Requests (Exchange Web Services).

static void ConvertId(ExchangeServiceBinding esb)
{
    // Create a request to convert identifiers.
    ConvertIdType request = new ConvertIdType();
    request.SourceIds = new AlternateIdType[1];
    request.SourceIds[0] = new AlternateIdType();

    // Convert from the Outlook Web Access identifier format to an PR_ENTRYID identifier.
    request.SourceIds[0].Format = IdFormatType.OwaId;
    (request.SourceIds[0] as AlternateIdType).Id = "RgAAAAAS2%";
    (request.SourceIds[0] as AlternateIdType).Mailbox = "User1@example.com";
    request.DestinationFormat = IdFormatType.EntryId;

    try
    {
        // Send the request and get the response.
        ConvertIdResponseType response = esb.ConvertId(request);

        ResponseMessageType[] rmta = response.ResponseMessages.Items;

        foreach (ResponseMessageType rmt in rmta)
        {
            ConvertIdResponseMessageType cirmt = (rmt as ConvertIdResponseMessageType);
            AlternateIdType myId = (cirmt.AlternateId as AlternateIdType);

            string format = myId.Format.ToString();
            string identifier = myId.Id;
            string mailbox = myId.Mailbox;

            Console.WriteLine("Converted to format: {0}\r\nIdentifier: {1}\r\nMailbox: {2}",
                format, identifier, mailbox);
            Console.ReadLine();
        }
    }

    catch (Exception e)
    {
        Console.WriteLine(e.Message);
        Console.ReadLine();
    }
}