title: Office 365 EWS calendar access giving ErrorTooManyObjectsOpened
body: <p>We are using the Exchange Web Service (EWS) API against Office 365 to create calendar events in the calendar of a user. This works fine for an on-premise deployment, but with an Office 365 deployment we seem to be hitting a throttling limit fairly quickly.</p>
  
  <p>After creating 16 events, in the calendar of 16 different users (from a service account, using delegate access to the calendars), we receive the following error:</p>
  
  <blockquote>
    <p>ErrorTooManyObjectsOpened - Too many concurrent connections opened</p>
  </blockquote>
  
  <p>After ~5 minutes, this error clears and we can continue creating events. It seems that the EWS server caches connections to mailboxes, and Office 365 only seems to allow a connection to 16 mailboxes at a time.</p>
  
  <p>We tried a lot to overcome this error, but have not found a 'final' solution or workaround. What we tried:</p>
  
  <ul>
  <li>Using impersonation instead of delegation: this works, but is a no-go from a security perspective.</li>
  <li>Using multiple service accounts: this works, although each account it still limited to ~16 users per 5 minutes.</li>
  <li>We tried the <code>X-AnchorMailbox</code> and <code>X-PreferServerAffinity</code> headers, and we making requests with and without HTTP keep alive, and with and without keeping the HTTP cookies.This does not make any difference. From the debug info we see that we usually end up on the same front-end and back-end server if we keep the cookies/connection, and that we end up on a different front-end if we drop the cookies but send a <code>X-AnchorMailbox</code> header.</li>
  <li>We have not yet tried the REST API, since the <a href="http://blogs.msdn.com/b/exchangedev/archive/2014/10/28/oauth2-in-action-with-the-release-of-office-365-calendar-contacts-and-mail.aspx" rel="nofollow">client credential flow is not available yet</a>.</li>
  </ul>
  
  <p>Only the <code>CreateItems</code> call seem to cause this problem, we can do a <code>FindItems</code> for many users without hitting a limit.</p>
  
  <p>Is anyone aware of a way to overcome this limitation, e.g., is there some call we can do to close the cached mailbox sessions on the Office 365 side? Or is there an Office 365 administrator in the room who can shed some light on the exact throttling limits, and why they are so much lower than the on-premise Exchange throttling limits?</p>
  
  <p>Other details: we are using a modified version of the <a href="https://github.com/OfficeDev/ews-java-api" rel="nofollow">EWS Java API</a>, but have done some extensive research and are quite sure this problem is server-side.</p>