[E2007][EWS][C#] Slow constructor performance when instantiating Exchange Web Service RRS feed

  • Question

  • Using VS 2008 SP1, I find that it takes a very long time (> 1 minute) to get past instantiating my Exchange Web Service instance which I then use to grab a user's Out of Office settings. I have a reference to C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.Dll (version in my project, which consists of a single windows form.

    As soon as the form_shown event is raised, I start a backgroundworker thread (RunWorkerAsync) which grabs the out of office settings via the single instance of the EWS helper class:

    Here's the code for the helper class:

    public class helper
        private static helper instance;
        private ExchangeService service;
        private string smtpAddr;
        private helper()
             ServicePointManager.ServerCertificateValidationCallback=delegate{(Object obj, X509Certificate cert,X509Chain chain,SslPolicyErrors polError)    
                 {return true; };
             service=new ExchangeService(ExchangeVersion.Exchange2007_SP1);
        // other methods including get /set out of office



    I ran the code against a profiling tool (Eqatec) and it reported that the constructor took over a minute. I could see this behaviour anyway since the background thread does not return until the out of office settings have been retrieved.

    I tried Ngen'ing the release .exe and webservice.dll but it doesn't appear to improve performance. I found an article on stackoverflow which discussed using sgen to create the XML serializers dll (for CRM, not Exchange) but following the instructions there resulted in missing c# code (e.g. autodiscover method was missing) so the replacement DLLs could not be compiled.

    Any ideas how I can improve the performance? thanks in advance

    - Charles

    Wednesday, March 21, 2012 4:12 PM