locked
EWS Managed API: Multiple ExchangeService objects a problem? Resource-Intensive? RRS feed

  • Question

  • Hi,
    during the processing of incoming Push Notification Events (the Event Handler is a thread safe delegate) I have to create a new ExchangeService object and set its ImpersonateId multiple times during the event to replicate the changes of this event back to other Exchange mailboxes. Are the ExchangeService objects expensive? The garbage collector should destroy those objects used in past events, shouldnt it? Code for the delegate would be sth like this:
     if (bocet.Item is ItemIdType)
                {
    
                    
                    ExchangeService tempService = new ExchangeService(exchVersion);
                    tempService.Credentials = credentials;
                    tempService.Url = new Uri(EWS_URL);
    
                    tempService.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, dicUsersSubscriptionIDs[subscriptionId]);
    
                    ItemIdType itemId = bocet.Item as ItemIdType;
                    
    
                    
                    DataTable dt=GetAffectedUsersSMTP();
    
                    foreach (DataRow rw in DataTable dt)
                     {
                      tempService.ImpersonatedUserId.Id=rw["SMTPAddress"].toString();
    
                       //Bind affected contact item of other users
                       //update contact item with tempservice
                       //move on to the next datarow
                     }
    
    }

    Thank you for your thoughts.
    Wednesday, August 5, 2009 2:05 PM

Answers

  • Hi,

    the ExchangeServiceBinding object is a rather light-weight class, so you can (and should) create multiple instances of this class. And whatever you do - the ExchangeServiceBinding uses the HttpWebRequest class which in turn uses the ServicePointManager to reuse existing connections.

    Kind regards,
    Henning Krause
    • Marked as answer by Hoetz Wednesday, August 5, 2009 4:14 PM
    Wednesday, August 5, 2009 3:39 PM

All replies

  • Hi,

    the ExchangeServiceBinding object is a rather light-weight class, so you can (and should) create multiple instances of this class. And whatever you do - the ExchangeServiceBinding uses the HttpWebRequest class which in turn uses the ServicePointManager to reuse existing connections.

    Kind regards,
    Henning Krause
    • Marked as answer by Hoetz Wednesday, August 5, 2009 4:14 PM
    Wednesday, August 5, 2009 3:39 PM
  • Thank you Henning.
    Wednesday, August 5, 2009 4:14 PM