[英]How to validate Exchange credentials and verify Exchange server communication using EWS managed API?
Using Exchange EWS managed API 2.0, here is a method which I'm using to validate credentials: 使用Exchange EWS托管API 2.0,这是我用来验证凭据的方法:
public static bool TestExchangeConnetion(UserSettingDTO credential, ServerSettingDTO serverSetting)
{
bool authenticated = false;
Microsoft.Exchange.WebServices.Data.ExchangeService service;
service = new ExchangeService((ExchangeVersion)Enum.Parse(typeof(ExchangeVersion), serverSetting.ExchangeVer));
service.Url = new Uri(serverSetting.ExchangeURL);
service.Credentials = new NetworkCredential(credential.ExchangeUsername, credential.ExchangePassword);
try
{
//make a call to ensure that credentials are working
AlternateIdBase response = service.ConvertId(new AlternateId(IdFormat.EwsId, "Placeholder", credential.ExchangeUsername), IdFormat.EwsId);
}
// The credentials were authenticated. We expect this exception since we are providing intentional bad data for ConvertId
catch (ServiceResponseException)
{
authenticated = true;
}
// The credentials were not authenticated.
catch (ServiceRequestException)
{
authenticated = false;
}
catch (Exception)
{
authenticated = false;
}
return authenticated;
}
This works absolutely fine to validate credentials but I'm looking for a way to differentiate between invalid credentials and Exchange server downtimes. 验证凭据绝对可以,但是我正在寻找一种方法来区分无效凭据和Exchange服务器停机时间。 This code returns false for both.
这段代码都返回false。 Is it possible to find out if there is an issue communicating to the server (like server downtimes)?
是否可以找出是否存在与服务器通信的问题(例如服务器停机时间)? The reason for this is I want to notify the user about invalid credentials not server downtimes!
原因是我想通知用户有关无效凭据的信息,而不是服务器停机时间!
EWS is just a Web-service that runs on IIS (so IIS is looking after authentication) if you just want to check the credentials why don't you just make a Get request against the services.wsdl file or a Get on the Autodiscover endpoint on the CAS server. EWS只是在IIS上运行的Web服务(因此IIS负责身份验证),如果您只想检查凭据,为什么不只针对services.wsdl文件发出Get请求或在Autodiscover端点上发出Get要求在CAS服务器上。 If the credentails are incorrect that should return a 401 at that point.
如果credentails不正确,那应该返回401。
Cheers Glen 干杯格伦
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.