简体   繁体   English

如何使用EWS托管API验证Exchange凭据和验证Exchange服务器通信?

[英]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.

相关问题 使用EWS托管API将.msg文件上传到Exchange Server - Upload .msg file to Exchange Server using EWS Managed API 使用EWS托管API验证登录凭据 - Validate login credentials using EWS Managed API 允许模拟用户通过EWS托管API 2.0登录到Exchange Server - Allow impersonation users to login to Exchange Server by EWS Managed API 2.0 使用EWS托管API将新联系人添加到Outlook邮箱并将其链接到Exchange Server - Add a new contact to an Outlook mailbox using EWS Managed API and link it to Exchange Server 如何使用 Exchange Online/EWS 托管 API 对控制台应用程序进行身份验证? - How to authenticate a console application with Exchange Online/EWS Managed API? Exchange EWS托管API-XML中的意外令牌 - Exchange EWS Managed API - unexpected token in XML 按日期获取Exchange EWS托管API 2.0 - Exchange EWS Managed API 2.0 get by date 如何使用EWS托管API访问Exchange GAL MailContact属性说明? - How to access Exchange GAL MailContact property Notes using EWS Managed API? 如何获取所有用户使用EWS API的Exchange服务器上的所有邮件? - How to get All users All mail on Exchange server using EWS API? EWS托管的Api-从Office365交换服务器中检索电子邮件 - EWS Managed Api - Retrieving e-mails from Office365 exchange server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM