首页 文章

如果联系人在GAL中,则Exchange Web服务(EWS)FindItems不起作用

提问于
浏览
1

我创建了一个从外部源获取Contact对象的小应用程序 . 然后,根据一些配置,我必须在我们的Exchange服务器上的用户联系人文件夹中创建/更新这些联系人,以便下次该用户打开其MS Outlook时,他会看到新的联系人(在Exchange服务器上,我有具有模拟功能的用户,因此安全性不是问题 .

为此,我使用EWS库的 FindItems(folderId, filter, view) 方法,该方法运行良好 . 对于过滤器,我是一个非常好的密钥...如果我得到一个结果,这只是意味着联系已经存在,我需要进行更新而不是创建 . 一切都按预期工作,直到这里......

但是,当GAL(全局地址列表)中已经存在联系人(实际上是电子邮件地址)时,我遇到了问题 . 在这种情况下,即使文件夹中存在联系人, FindItems 方法也不会返回结果!似乎(这是一个假设)交换服务器为联系人创建一个链接,该联系人的电子邮件地址已经存在于GAL中,而不是新的联系人 . 这可以解释为什么 FindItems 方法在这种情况下不返回任何内容 . The strange thing is that if I'm filtering on another property (for example on the combination of first and lastname), it works!

目前,会发生的情况是,对于GAL中已存在的每个联系人,创建而不是更新(因为 FindItems 方法不返回任何内容),因此,创建相同的联系人X时间(而不是创建)一次,然后更新X-1时间) .

问题当然是,如果联系人在GAL中已存在联系人文件夹,我怎么知道联系人是否存在?

当前代码:

ItemView view = new ItemView(5)
{
   PropertySet = new PropertySet(BasePropertySet.FirstClassProperties)
};
SearchFilter f = new SearchFilter.IsEqualTo(ContactSchema.EmailAddress1, email);
FindItemsResults<Item> contactItems = _service.FindItems(folderId, f, view);
int resultCount = contactItems.Count(); // Always 0 if GAL, otherwise it works

1 回答

  • 0

    最后,我使用 SetExtendedProperty 方法解决了扩展属性的问题 . 在这个扩展的领域,我只是放了 Id ,这解决了问题 .

    But that does not explain why the search is not working with an email address ...如果有人知道答案,我仍然感兴趣:)

    新搜索如下所示:

    ItemView view = new ItemView(nb);
    view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, _extendedPropDef);
    SearchFilter f = new SearchFilter.IsEqualTo(_extendedPropDef, contact.Id);
    FindItemsResults<Item> contactItems = _service.FindItems(folderId, f, view);
    

    使用此代码,一切都按预期工作......

相关问题