【问题标题】:GetRoomLists succeeds but returns no dataGetRoomLists 成功但不返回数据
【发布时间】:2013-03-02 00:33:00
【问题描述】:

我正在使用 Exchange Web 服务调用 GetRoomLists,我们正在运行 Exchange 2010。下面的代码正在通过控制台应用程序执行。根据“No Error”的 XML 响应,调用成功,但没有返回数据。当您尝试通过 Outlook 约会添加一个房间时,我们列出了数百个房间,所以不知道为什么会发生这种情况。

我已尝试使用 EWS DLL 版本 1.2 和 2.0,使用默认凭据或传入凭据。在最初发布此内容后,我注意到响应标头说我们正在使用 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

【问题讨论】:

  • 您是否尝试过使用不同的帐户?也许主叫身份没有查看任何房间列表的权限?在这种情况下,服务器将只返回空列表,如您的跟踪中所见。 msdn.microsoft.com/en-us/library/exchange/… 将您的响应列为服务器上没有任何房间列表的典型响应。
  • @RomanGruber - 刚刚阅读了更多关于房间列表实际上是什么的内容,我如何才能像 Outlook 一样在没有房间列表的情况下获得房间列表?

标签: c# web-services exchangewebservices


【解决方案1】:

嗯,我找到了原因/解决方案。混淆之处在于 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;
}

【讨论】:

  • @user301639 - 我的答案中第二个链接的 LDAP 查询确实从 AD 中带回了房间,所以看起来它正在工作。
  • 我迷失了代码,步骤顺序出现了一些死锁,字符串 roRootDSE = dsDirectorySearcher.SearchRoot.Path; DirectoryEntry deDirectoryEntry = new DirectoryEntry(roRootDSE); DirectorySearcher dsDirectorySearcher = new DirectorySearcher(deDirectoryEntry);你是怎么解决的?谢谢!
  • @user301639 - 我没有遇到任何异常。我已经发布了代码,希望对您有所帮助。
  • 彼得,感谢您的帮助,您发送的过滤器到底是什么?谢谢
  • @Igal - 您根本不需要为此提供过滤器,但是在我工作的地方,我们的会议室使用 Site-Building-Room 的命名约定,过滤器就是这样可以传入一个格式化的字符串来限制结果。出于测试目的,尝试将 String.Empty 作为您的过滤器,看看会返回什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-26
  • 1970-01-01
  • 2016-03-23
  • 2020-04-28
  • 2022-11-22
  • 2016-07-28
相关资源
最近更新 更多