Pergunta

I am using EWS api for email operations.
When initially user sets up his account, i just need to collect latest syncstate of his account. My CRON job checks for latest changes from then onwards at regular intervals.
Here is the code

var service         = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Url         = new Uri("https://" + data.ServerAddress + "/ews/Exchange.asmx");
service.Credentials = new NetworkCredential(data.EMail, data.Password);
ServicePointManager.ServerCertificateValidationCallback = (xyzxyz, certificate, chain, sslPolicyErrors) => true;
ChangeCollection<ItemChange> icc = service.SyncFolderItems(new FolderId(WellKnownFolderName.Inbox),
                                                           PropertySet.FirstClassProperties,
                                                           null,
                                                           512,
                                                           SyncFolderItemsScope.NormalItems,
                                                           null );
return icc.SyncState;

Issue lies in collecting SyncState when user initially sets up his account.
Assume user has 600 email in Inbox. When I request for syncstate with above code, I get syncstate which is valid for first 512 emails. I will have to make one more call to get next syncstate which is valid and final. This will increase waiting time for the user to setup his account. If user has 10000 mails in Inbox, it would be required to make 20 calls to EWS to get final SyncState.
How to get final or latest SyncState with a single call to EWS?

Foi útil?

Solução

You can't get the latest sync state in a single call, see EWS. How to get latest SyncState without initial synchronization?. Note that starting with Exchange 2010 SP2, EWS returns items from newest to oldest, so the user will get their newest items first - they won't have to wait all 20 calls.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top