开发者

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

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;
    }


Unfortunately, no. The only thing I can think of is to resolve the mail address using LDAP. This might be faster.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜