简体   繁体   中英

Exchange Web Service API and 401 unauthorised but succeeding

Connecting to Exchange Web Services for Office 365 reports multiple dependency failures in Application Insights.

The code below actually works and does return folder and message results. But we're constantly seeing huge numbers of failures reported by Application Insights when we hit the endpoints.

在此处输入图片说明

service = new ExchangeService(ExchangeVersion.Exchange2013_SP1, TimeZoneInfo.Local);
service.Credentials = new WebCredentials(account, password, "domain_foo");
service.Url = new Uri(@"https://outlook.office365.com/EWS/Exchange.asmx");

I would expect this to just not fail, but the fact that we get mailbox data back AND see dependency call failures is just bizarre. Application Insights doesn't allow us to drill down further to see what the problem was, but we're seeing a failure rate of 50/s to 75/s

If the request are not failing then 401's are normal during credential negotiation eg the first request will return a 401 as a Challenge with the headers telling the requester what authentication is available on the server see https://blogs.msdn.microsoft.com/benjaminperkins/2011/09/14/integrated-windows-authentication-with-negotiate/

If you using Office365 then don't use Basic authentication its going away next year https://techcommunity.microsoft.com/t5/Exchange-Team-Blog/Upcoming-changes-to-Exchange-Web-Services-EWS-API-for-Office-365/ba-p/608055 you should look to use OAuth instead or even look at using the Graph if you can.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM