EWS: Exchange Web Service. Calling ResolveName multiple Times - Perfomance Hit (of course)

怎甘沉沦 提交于 2020-01-03 17:43:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!