c# - GetRoomLists 成功但没有返回数据

标签 c# web-services exchangewebservices

我正在使用 Exchange Web 服务调用 GetRoomLists,我们正在运行 Exchange 2010。以下代码正在通过控制台应用程序执行。根据“无错误”的 XML 响应,调用成功,但未返回任何数据。当您尝试通过 Outlook 约会添加一个房间时,我们列出了数百个房间,因此不确定为什么会发生这种情况。

我尝试过同时使用 EWS DLL 1.2 和 2.0 版,使用默认凭据或传入凭据。我最初发布此消息后注意到响应 header 显示我们正在使用 Exchange 2012 SP2,因此我尝试更新我的代码以使用该 ExchangeVersion 枚举值,但结果没有变化。

我已经成功地在此 Exchange 服务器上使用 EWS 读取邮箱,但之前从未读取过房间。

C#

        ExchangeService es = new ExchangeService(ExchangeVersion.Exchange2010);
        es.TraceFlags = TraceFlags.EwsResponse | TraceFlags.EwsRequest;
        es.TraceEnabled = true;
        es.UseDefaultCredentials = true;
        es.AutodiscoverUrl("autodiscover@example.com");
        //this collection is empty after processing
        EmailAddressCollection eac = es.GetRoomLists();

来自 Web 服务请求/响应的 XML 跟踪

<Trace Tag="EwsRequest" Tid="9" Time="2013-03-13 20:39:41Z" Version="14.03.0032.000">
  <?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
      <t:RequestServerVersion Version="Exchange2010" />
    </soap:Header>
    <soap:Body>
      <m:GetRoomLists />
    </soap:Body>
  </soap:Envelope>
</Trace>

<Trace Tag="EwsResponse" Tid="9" Time="2013-03-13 20:39:41Z" Version="14.03.0032.000">
  <?xml version="1.0" encoding="utf-8"?>
  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
      <h:ServerVersionInfo MajorVersion="14" MinorVersion="2" MajorBuildNumber="328" MinorBuildNumber="9" Version="Exchange2010_SP2" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <GetRoomListsResponse ResponseClass="Success" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
        <ResponseCode>NoError</ResponseCode>
        <m:RoomLists xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" />
      </GetRoomListsResponse>
    </s:Body>
  </s:Envelope>
</Trace>

有关 GetRoomLists 的 MSDN 文档:http://msdn.microsoft.com/en-us/library/dd899416(v=exchg.140).aspx

最佳答案

好吧,我找到了原因/解决方案。混淆之处在于 GetRoomLists 不返回房间列表,而是返回房间列表的列表或“房间列表”的集合。这些是包含房间列表的特殊类型的分发列表。

如此处所述,http://social.msdn.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/4ff04c60-48c2-4a69-ab75-2383e73bfde2 ,您要么需要设置房间列表,要么需要查询 AD 并检查 msExchRecipientDisplayType 属性以跟踪房间。

此链接显示了如何编写 LDAP 查询以返回房间的示例:http://social.msdn.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/e2d10953-a8f9-459c-8a0e-f10c2e568b26

我放在一起寻找房间的代码:

private List<string> GetConfRooms(string filter)
{
    List<string> sRooms = new List<string>();

    DirectoryEntry deDomain = System.DirectoryServices.ActiveDirectory.Domain.GetComputerDomain().GetDirectoryEntry();
    DirectorySearcher dsRooms = new DirectorySearcher(deDomain);

    dsRooms.Filter = string.Format("(&(&(&(mailNickname={0}*)(objectcategory=person)(objectclass=user)(msExchRecipientDisplayType=7))))", filter);

    dsRooms.PropertiesToLoad.Add("sn");
    dsRooms.PropertiesToLoad.Add("mail");

    foreach (SearchResult sr in dsRooms.FindAll())
    {
        sRooms.Add(sr.Properties["mail"][0].ToString());
    }

    return sRooms;
}

关于c# - GetRoomLists 成功但没有返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15396073/

相关文章:

c# - Windows服务线程与循环和WCF

web-services - "The file has not been pre-compiled, and cannot be requested"

c# - 尝试使用 Exchange Web 服务获取电子邮件时出现 ServiceObjectPropertyException?

web-services - soap:address 和 http:address

java - 强制 AXIS 客户端使用 TLS

java - 无法建立与 Exchange Web 服务的连接 - Java API

c# - EWS 托管 API : Setup user email alias

c# - 在 winform RichTextBox 中更改行间距

c# - linq嵌套列表包含

c# - 如何在C# Windows 窗体应用程序的SQL Server 中获取今天插入数据的记录