本文介绍了EWS:交易所Web服务。调用ResolveName多次 - 性能比较命中(当然)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Stackoverflow社区,

Hi Stackoverflow community,

我通过EWS从一个Outlook帐户加载所有Exchange Outlook联系人。不幸的是,当联系人的电子邮件地址在我们自己的Active Directory内时,它会转换为不同的格式(/ o = ...; ou = ...; cn = ...)。
要将此转换为常规电子邮件地址,我使用EWS服务对象的ResolveName方法。

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.

现在问题:我循环所有FindItems结果的项目,将返回的数据映射到我自己的C#类。在这个循环中,我必须调用ResolveName方法,它总是导致对EWS的调用。说到几个联系人,这需要一些时间。

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.

我已经缓存了之前已解决的地址。但是,仍然,这种性能打击第一次调用,当然。
问题显然是:有没有办法减少这个名字 - 解决到呼吁ews?

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?

提前感谢!

我在循环中调用:

EmailAddress email;
if (contact.EmailAddresses.TryGetValue(EmailAddressKey.EmailAddress1, out email))
{
    person.Email = GetResolvedEmailAddress(email.Address, svc);
}

GetResolvedName方法(用于缓存):

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


推荐答案

我唯一能想到的是使用LDAP解析邮件地址。此可能更快。

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

这篇关于EWS:交易所Web服务。调用ResolveName多次 - 性能比较命中(当然)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 23:58