Click to Rate and Give Feedback
MSDN
MSDN Library
Exchange Server
Programming Tasks
 Versioning Requests (Exchange Web S...

  Switch on low bandwidth view
Exchange Server 2007 SP1
Versioning Requests (Exchange Web Services)

Topic Last Modified: 2007-11-01

Microsoft Exchange Server 2007 Service Pack 1 (SP1) introduces Exchange Web Services request versioning. Versioning provides a way to indicate to the computer that is running Exchange 2007 SP1 the type of response that an Exchange Web Services client expects. For example, an Exchange 2007–generated proxy throws an exception if it deserializes a request that includes new Exchange 2007 SP1 elements. Exchange Web Services uses the versioning SOAP header to generate responses that are valid for the specified version. Exchange 2007 SP1 includes a new SOAP header that identifies the schema against which the request is validated and restricts the response based on that schema. In addition to new objects and operations that are available in Exchange 2007 SP1, there are some API behavior changes between the Exchange Web Services schema versions. These changes include the Exchange Web Services identifier format and how time zones are implemented.

Requests that do not include version headers are handled as requests from the initial release version of Exchange 2007. If the Exchange2007_SP1 version is not specified, schema validation errors might occur because the request will be validated against the initial release version of the Exchange Web Services schema instead of the Exchange 2007 SP1 version of the schema. Other errors might also occur because Exchange 2007 SP1 identifiers will be processed as identifiers for the initial release version of Exchange 2007.

The following procedures describe how to add versioning information to the ExchangeServiceBinding object and how to add versioning information directly to the SOAP header.

  1. Create an instance of an ExchangeServiceBinding object.

                ExchangeServiceBinding esb = new ExchangeServiceBinding();
              
  2. Create an instance of a new RequestServerVersion object.

    esb.RequestServerVersionValue = new RequestServerVersion();
  3. Set the Version property on the RequestServerVersion object to one of the following ExchangeVersionType enumeration values:

    • Exchange2007_SP1
    • Exchange2007

    The Version property is set to Exchange2007_SP1 by default.

  4. Set the RequestServerVersion object to the RequestServerVersionValue property on the ExchangeServiceBinding.

    esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007_SP1;
  1. Create the SOAP header.

  2. Create the RequestServerVersion XML element as the first inner XML element in the SOAP header.

  3. Create a Version attribute in the RequestServerVersion element.

  4. Set the Version attribute to either Exchange2007 or Exchange2007_SP1.

The following code example shows you how to version an Exchange 2007 SP1 Exchange Web Services request by using the ExchangeServiceBinding object that is created by using WSDL.exe version 2.0.50727.42. The example will not work if the proxy classes are generated against the Exchange Web Services schemas that are included in the initial release version of Exchange 2007. The code example performs an identifier conversion between the Exchange Web Services identifier format and the Outlook Web Access identifier format.

C#
static void UsingVersioning()
{
    // Set the version, credentials, and the Client Access server on ExchangeServiceBinding.
    ExchangeServiceBinding esb = new ExchangeServiceBinding();
    esb.RequestServerVersionValue = new RequestServerVersion();
    esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007_SP1;
    esb.Credentials = new NetworkCredential("username", "password", "domain");
    esb.Url = "https://FQDN/ews/exchange.asmx";

    // Create a request to convert identifiers.
    ConvertIdType request = new ConvertIdType();
    request.SourceIds = new AlternateIdType[1];
    request.SourceIds[0] = new AlternateIdType();

    // Convert from the initial release version of Exchange 2007 identifier format to an Outlook Web Access identifier.
    request.SourceIds[0].Format = IdFormatType.EwsLegacyId;
    (request.SourceIds[0] as AlternateIdType).Id = "AAAlAFVz";
    (request.SourceIds[0] as AlternateIdType).Mailbox = "user@example.com";
    request.DestinationFormat = IdFormatType.OwaId;

    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);
        }
    }

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

The following example shows you the XML that is sent for an Exchange 2007 SP1 Exchange Web Services request. The version information is located in the SOAP header.

<?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>
    <ConvertId xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
               xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
               DestinationFormat="OwaId">
      <SourceIds>
        <t:AlternateId Format="EwsLegacyId" Id="AAAlAFVz" 
                       Mailbox="user@example.com"/>
      </SourceIds>
    </ConvertId>
  </soap:Body>
</soap:Envelope>

The following example shows you the XML response to an Exchange 2007 SP1 Exchange Web Services request. The version information is located in the SOAP header.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Header>
    <t:ServerVersionInfo MajorVersion="8" MinorVersion="1" 
                         MajorBuildNumber="191" MinorBuildNumber="0" 
                         Version="Exchange2007_SP1" 
                         xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" />
  </soap:Header>
  <soap:Body>
    <m:ConvertIdResponse xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" 
                         xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
      <m:ResponseMessages>
        <m:ConvertIdResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:AlternateId xsi:type="t:AlternateIdType" Format="OwaId" Id="RgAAAAAS2%2" 
                         Mailbox="user@example.com" />
        </m:ConvertIdResponseMessage>
      </m:ResponseMessages>
    </m:ConvertIdResponse>
  </soap:Body>
</soap:Envelope>
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker