Search code examples
c#exchangewebservicesews-managed-api

EWS Managed API: Can I load properties for multiple items with one EWS call, given only the item IDs?


Does anyone know of any way to bind to multiple items in a single EWS call, using the EWS Managed API, given only the ItemIds of the items in question?

Here's how my application works at the moment:

  • Call ExchangeService.FindItems() repeatedly to generate a potentially very large list of items (hundreds of thousands or more).
  • Store the ItemIds in a database (as strings).
  • Read each ItemId in turn from the database, bind to the item using Item.Bind() and process it (details of processing not important).

Trouble is, it doesn't take very long to process each item, so my code is spending about half of its time in Item.Bind(). It's probably not making the Exchange mailbox server tremendously happy either, having to satisfy a constant barrage of tiny queries. It seems to me it would be far more efficient to "batch up" the requests, loading properties for maybe 100 or so items at a time.

Right now, I'm sure you're asking - why not just skip the database and call ExchangeService.LoadPropertiesForItems() after each FindItems() call? Well... there's a definite possibility that this thing will be stopped before it's finished processing all the items. When it starts up again (maybe hours or days later), it needs to be able to resume from the point where it left off. The code that's using FindItems() is sufficiently non-trivial that it would be a total nightmare to figure out how to save its state for later resumption.

I've found Loading Properties for Multiple Items with One Call to Exchange Web Services, which explains that LoadPropertiesForItems() is using the EWS GetItem call behind the scenes. That does accept a list of ItemIds, but that functionality doesn't seem to be exposed through the Managed API (LoadPropertiesForItems() requires a list of already-bound Item objects, not just ItemIds).

So a few questions really:

  1. Am I missing something? Is there actually a method somewhere in the EWS Managed API that does what I'm looking for?
  2. If not, once I've got an Managed API session going, is there a way to "piggy back" a raw EWS SOAP call on that without having to go through all the authentication etc. again, the hard way?
  3. Am I just Doing It Wrong in some spectacular way? :-)

Solution

  • ExchangeService.BindToItems is what you're looking for.