EWS - 获取用户的同行(同一经理)

时间:2013-04-05 00:46:53

标签: c# .net exchangewebservices

我正在尝试进行交换查询以获取用户的同行,因为它显示在全局地址列表中。 我的第一个想法是运行一个返回具有相同管理器的所有用户的查询。

FindItemType request = new FindItemType();
DistinguishedFolderIdType[] fid = { new DistinguishedFolderIdType { Id = DistinguishedFolderIdNameType.contacts } };

request.ParentFolderIds = fid;
request.Traversal = ItemQueryTraversalType.Shallow;

ItemResponseShapeType props = new ItemResponseShapeType();
props.BaseShape = DefaultShapeNamesType.AllProperties;

request.ItemShape = props;

// insert restriction where "someone@somewhere.com" = contactsManager

FindItemResponseType response = _binding.FindItem(request);

不幸的是,这会查询我的联系人列表,而不是GAL。 我怎么能正确地做到这一点?

我无法查询AD(应用程序旨在运行内部网络),而且出于各种原因我也不使用EWS托管API。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

以下是如何使用EWS for Exchange 2007及更高版本访问GAL的示例; Taken From Here请参阅链接以获取一些有效指针。此代码在GAL中搜索特定联系人。

static void Main(string[] args)
{
    ExchangeServiceBinding esb = new ExchangeServiceBinding();
    esb.Url = @"https://myserver/EWS/Exchange.asmx";
    esb.Credentials = new NetworkCredential(
                          "username",
                          @"password",
                          @"domain");

    // Create the ResolveNamesType and set
    // the unresolved entry.
    ResolveNamesType rnType = new ResolveNamesType();
    rnType.ReturnFullContactData = true;
    rnType.UnresolvedEntry = "test";

    // Resolve names.
    ResolveNamesResponseType resolveNamesResponse = esb.ResolveNames(rnType);
    ArrayOfResponseMessagesType responses = resolveNamesResponse.ResponseMessages;

    // Check the result.
    if (responses.Items.Length > 0 && responses.Items[0].ResponseClass != ResponseClassType.Error)
    {
        ResolveNamesResponseMessageType responseMessage = responses.Items[0] as ResolveNamesResponseMessageType;

        // Display the resolution information.
        ResolutionType[] resolutions =
        responseMessage.ResolutionSet.Resolution;

        foreach (ResolutionType resolution in resolutions)
        {
            Console.WriteLine("Name: " + resolution.Contact.DisplayName);
            Console.WriteLine("EmailAddress: " + resolution.Mailbox.EmailAddress);

            if (resolution.Contact.PhoneNumbers != null)
            {
                foreach (PhoneNumberDictionaryEntryType phone in resolution.Contact.PhoneNumbers)
                {
                    Console.WriteLine(phone.Key.ToString() + " : " + phone.Value);
                }
            }

            Console.WriteLine("Office location:" + resolution.Contact.OfficeLocation);
            Console.WriteLine("\n");
        }
    }
}