c# – GetRoomLists成功但不返回任何数据

前端之家收集整理的这篇文章主要介绍了c# – GetRoomLists成功但不返回任何数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用Exchange Web服务调用GetRoomLists,我们正在运行Exchange 2010.以下代码正在通过控制台应用程序执行.根据“无错误”的 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

解决方法

好吧,我找到了原因/解决方案.令人困惑的是,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;
}
原文链接:https://www.f2er.com/csharp/243879.html

猜你在找的C#相关文章