问题
Hi Stackoverflow community,
I am loading all Exchange Outlook Contacts from ones Outlook Account via EWS. Unfortunately, when a Contact's Email-Address is inside of our own Active Directory, it gets converted into a different format (/o=...;ou=...;cn=...). To convert this into a regular email-address, i am using the ResolveName Method of the EWS-Service Object.
Now the problem: I am looping through all Items of the result of FindItems to map the returned data onto my own C# Classes. Inside of this loop, I have to call the ResolveName-Method, which always leads to a call to EWS. Speaking of several Contacts, this takes some time.
I am already caching addresses that have been resolved before. But still, there is this performance hit on first call, of course. Question is obviously: Is there a way to reduce this name-resolving to on call to ews?
Thanks in advance!
My call inside of the loop:
EmailAddress email;
if (contact.EmailAddresses.TryGetValue(EmailAddressKey.EmailAddress1, out email))
{
person.Email = GetResolvedEmailAddress(email.Address, svc);
}
The GetResolvedName-Method (used for caching):
private static Dictionary<String, String> ResolvedEmailAddressCache = new Dictionary<String, String>();
private static String GetResolvedEmailAddress(string address, ExchangeService svc)
{
if (ResolvedEmailAddressCache.ContainsKey(address))
return ResolvedEmailAddressCache[address];
NameResolutionCollection nd = svc.ResolveName(address);
foreach (NameResolution nm in nd)
{
if (nm.Mailbox.RoutingType == "SMTP")
{
ResolvedEmailAddressCache.Add(address, nm.Mailbox.Address);
return nm.Mailbox.Address;
}
}
ResolvedEmailAddressCache.Add(address, address);
return address;
}
回答1:
Unfortunately, no. The only thing I can think of is to resolve the mail address using LDAP. This might be faster.
来源:https://stackoverflow.com/questions/7255169/ews-exchange-web-service-calling-resolvename-multiple-times-perfomance-hit