3
votes

I am attempting to write a method to find the Exchange Server version an Exchange Server I'm connecting to with EWS.

It is clear that reading the contents of a response XML to an EWS request contains this info, as described here.

I'm curious if I must test and error handle or if there's another "less invasive" method to find the Exchange version.

How do I find the version of an Exchange Server I am attempting to access with EWS so that I can set it for EWS managed API activity?

I am currently using the following, but I can't imagine this is the most efficient way?

foreach (ExchangeVersion exchver in Enum.GetValues(typeof(ExchangeVersion)))
{
    //Console.WriteLine(exchver.ToString());
    try
    {
        ExchangeService service = new ExchangeService(exchver);
        //Do stuff here
    }
    catch (Exception e)
    {
        Console.WriteLine("Server is not " + exchver +". Trying next ExchangeVersion.");
    }
}
1

1 Answers

5
votes

The tactic I take is to select a version of EWS that I "prefer" and ask for that first. Since later Exchanges are backwards compatible with their earlier releases, it's OK to ask E2013 to speak in E2010 SP2 "dialect" with you over EWS.

The big divide in EWS versions was between E2007 SP1 and E2010 RTM and later, notably in the management of time zones. If you can avoid supporting E2007 entirely, you can ask for the lowest common denominator, E2010 SP1, and talk amiably with higher levels. If you need to talk to E2007, then you'll have to try for E2010 SP1 first, then handle the exception as you do above. Of course YMMV, as there are some differences in the E2010+ APIs as shown here, so it's possible you might prefer a higher level.

After auto-discovery is complete, you can get the actual version of Exchange on the other end and adjust accordingly, e.g. if you ask for E2010 SP1 but wind up talking to an E2013, there are some affinity issues on notifications that need to be managed differently due to the architecture changes between E2010 and E2013, but that can be done in the E2010 SP1 dialect.

I also provide for a config value in my code to give a "hint" as to which version to try first, on the assumption that in a particular shop the Exchange servers are likely all at the same level.