我想使用具有基本身份验证的EWS托管API连接到Exchange Online。
但是在我的应用程序中,当使用基本身份验证时,EWS AutodiscoverService
无法从Exchange Online检索邮箱设置(GetUserSettings
),但是oAuth可以正常工作。
我收到一条带有以下消息的Microsoft.Exchange.WebServices.Data.ServiceRequestException
:连接尝试失败,因为连接的用户在一段时间后未正确响应,或者建立的连接失败,因为连接的主机未能响应40.101.50.162:444 “
我使用基本身份验证已经有好几年了,几天前它刚刚停止工作。在Exchange Online和EWS上不再可以使用基本身份验证吗?
代码示例
var ads = new AutodiscoverService
{
RedirectionUrlValidationCallback = url => true,
EnableScpLookup = false
};
ads.Credentials = new NetworkCredential( svcUsr, svcPwd ); // using these will throw an exception
ads.Credentials = new OAuthCredentials( token.AccessToken ); // these works
var res = ads.GetUserSettings( mailBox, UserSettingName.GroupingInformation );
例外
Microsoft.Exchange.WebServices.Data.ServiceRequestException: The request failed. Unable to connect to the remote server ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 40.101.28.194:444
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetRequestStream()
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverRequest.InternalExecute()
--- End of inner exception stack trace ---
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverRequest.InternalExecute()
at Microsoft.Exchange.WebServices.Autodiscover.GetUserSettingsRequest.Execute()
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetUserSettings(List`1 smtpAddresses, List`1 settings, Nullable`1 requestedVersion, Uri& autodiscoverUrl)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetSettings[TGetSettingsResponseCollection,TSettingName](List`1 identities, List`1 settings, Nullable`1 requestedVersion, GetSettingsMethod`2 getSettingsMethod, Func`1 getDomainMethod)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(List`1 smtpAddresses, List`1 settings)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetSoapUserSettings(String smtpAddress, List`1 requestedSettings)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames)
at EWSAutoDiscovery.Program.Main(String[] args) in C:\Program.cs:line 57
经过测试和验证的[更新1]