有Office 365 EWS问题(其唯一的Office 365,Exchange 2010和2013正常工作)。我可以毫无错误地创建我的订阅订阅,但是当我通过调用
来使用它时getEvents()
我收到错误:
ErrorNoRespondingCASInDestinationSite
检索事件以进行交换时发生以下错误 资源: - Exchange Web服务当前不是 可用于此请求,因为没有客户端访问服务器 在目标站点中可以处理请求。
以下是一些代码段
使用自动发现和设置凭据
this.exchangeService.Credentials = new NetworkCredential(this.Username, this.Password);
try {
this.exchangeService.AutodiscoverUrl(this.Username, RedirectionCallback);
}
catch(Exception ex)
{
Logger.WriteToEventLog(EventLogEntryType.Warning, 104, "ExchangeDataAccess, AutodiscoverURL error: " + ex.Message);
}
if (exchangeService.Url == null)
{
this.ExchangeServerURL = GetOffice365EWSUrl(this.Username);
this.exchangeService.Url = new Uri(this.ExchangeServerURL);
this.exchangeService.CookieContainer = new CookieContainer();
}
之后我们登录并找到我们的交换用户,我们将在
下执行所有操作ServicePointManager.ServerCertificateValidationCallback = (sender1, certificate, chain, errors) => true;
string username = this.Username;
if (this.authenticateContext.GetExchangeServerVersion().Contains("365"))
{
username = this.Username.Remove(this.Username.IndexOf("@"));
}
NameResolutionCollection resolveNameResult = this.exchangeService.ResolveName(username, ResolveNameSearchLocation.ContactsThenDirectory, true);
if (resolveNameResult.Count() > 0)
{
roomEmailAddress = resolveNameResult[0].Mailbox.Address;
if (!string.IsNullOrEmpty(roomEmailAddress))
{
this.ExchangeUserEmailAddress = roomEmailAddress;
logMsg.AppendLine("Logged into Exchange with " + roomEmailAddress + " successfully, RetrieveRoomsList is next");
}
}
然后我们获得一个SubscribeResponse并将其保存到列表中
subscribeResponse = this.exchangeDataAccess.ExchangeSubscribe(syncPoint.ThirdPartyId, syncPoint.Watermark, true);
我们将上述对象传递给包装器方法以从EWS获取所有事件
Dictionary<PullSubscription, IEnumerable<ItemEvent>> mailboxEvents = null;
GetEventsResults eventsResults = subscription.GetEvents();
if (eventsResults == null || eventsResults.ItemEvents.Count() == 0) {
return mailboxEvents;
}
mailboxEvents = new Dictionary<PullSubscription, IEnumerable<ItemEvent>>();
mailboxEvents.Add(subscription, eventsResults.ItemEvents);
return mailboxEvents;
调用subscription.GetEvents()
的行是返回顶部指示的异常的位置
还添加了另一层复杂性,因为我们的Exchange用户的域名为@ FOOlab.onmicrosoft.com,因为所管理的所有房间都有@ LAB.FOO.COM的域名
根据客户的说法,这是ADFS身份验证,但我对此并不了解。
然而,我可以说这个代码库确实有效(得到了事件),然后似乎有些东西发生了变化,错误就开始出现了。最初我认为客户改变了一些东西但是我们已经针对另一个Office 365(没有ADFS)进行了测试并看到了同样的错误,所以现在我不知道该怎么想。
答案 0 :(得分:3)
下面的链接可以解释它远远好于我,但到目前为止我已经解决了我的问题是围绕GetEvents
添加和删除标题数据X-AnchorMailbox
MSDN Link1 Link2
public Dictionary<PullSubscription, IEnumerable<ItemEvent>> GetEvents(SyncPoint syncpoint)
{
Dictionary<PullSubscription, IEnumerable<ItemEvent>> mailboxEvents = null;
if (this.authenticateContext.GetExchangeServerVersion().Contains("365"))
{
try
{
//this is to maintain affinity (see here https://msdn.microsoft.com/en-us/library/office/dn458789(v=exchg.150).aspx)
//it was added to fix an error: The following error occured while retrieving events for exchange resource: <room address> - Exchange Web Services are not currently available for this request because none of the Client Access Servers in the destination site could process the request.
//according to docs it is only when getting notifications that its important
if (this.exchangeService.HttpHeaders.Any(m => m.Key.Equals("X-AnchorMailbox")))
{
this.exchangeService.HttpHeaders.Remove("X-AnchorMailbox");
}
this.exchangeService.HttpHeaders.Add("X-AnchorMailbox", syncpoint.ThirdPartyId); //this is the email address of the mailbox being queried
}
catch { }
}
GetEventsResults eventsResults = syncpoint.pullSubscription.GetEvents();
if (eventsResults == null || eventsResults.ItemEvents.Count() == 0)
{
return mailboxEvents;
}
mailboxEvents = new Dictionary<PullSubscription, IEnumerable<ItemEvent>>();
mailboxEvents.Add(syncpoint.pullSubscription, eventsResults.ItemEvents);
try
{
this.exchangeService.HttpHeaders.Remove("X-AnchorMailbox");
} catch { }
return mailboxEvents;
}