【问题标题】:C# EWS ExchangeService: How do I know if it's authenticated?C# EWS ExchangeService:我如何知道它是否已通过身份验证?
【发布时间】:2021-07-17 04:21:52
【问题描述】:

我需要在 EWS ExchangeService 中进行身份验证,当我使用下面的代码时,我没有收到任何错误,但我没有看到服务变量上的任何属性表明其是否经过身份验证。即使我传递了错误的凭据,它也会执行相同的操作。没有错误,也没有属性表明它是否已通过身份验证。

public static ExchangeService GetService()
{
    ExchangeService service = new ExchangeService();
    service.Url = new Uri(@"https://someDomain.com/ews/Exchange.asmx");
    service.Credentials = new WebCredentials("someEmail", "somePassword");
    return service;
}

我对此进行了广泛的搜索,但没有发现任何关于身份验证的有用信息。

【问题讨论】:

    标签: c# exchangewebservices


    【解决方案1】:

    执行任何需要实时连接的操作,看看它是否返回错误。

    【讨论】:

    • 感谢@Dmitry Streblechenko。你能定义“操作”吗?我执行了上面的代码,即使凭据无效也没有出错。
    • 您需要做一些实际从服务器检索数据或将数据推送到服务器的操作。 EWS 库是延迟初始化的 - 您不需要执行任何实际需要连接到服务器的操作。
    • 谢谢@Dmitry。这导致了解决方案。
    【解决方案2】:

    Dmity 的评论导致了解决方案。

    ExchangeService service = new ExchangeService();
    service.Url = new Uri(@"https://luca1.cmtaegrs.com/ews/Exchange.asmx");
    service.Credentials = new WebCredentials("xcatest@cmtaegrs.com", "Cdaqt5e3swt5%");
    
    //Add the operation as @Dmity suggested
    EmailMessage message = new EmailMessage(service);
    message.Subject = "Interesting";
    message.Body = "This is a test for authenticating.";
    message.ToRecipients.Add("george.padvorac@crocodiledigital.net");
    
    //See if we have the correct credentials
    try
    {
        message.Send();
        _credentials_good = true;
    }
    catch (Exception ex)
    {
        _credentials_good = false;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-12-17
      • 2016-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      相关资源
      最近更新 更多