升级到O365破坏了EWS自动发现

时间:2018-06-29 18:44:15

标签: c# exchangewebservices autodiscovery

我的公司刚刚将一些邮箱移至O365。不幸的是,这破坏了使用EWS创建的应用程序。尝试调出AutodiscoverUrl()时,遇到错误。

  

“找不到自动发现服务。”

代码:

        service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
        service.UseDefaultCredentials = true;
        service.AutodiscoverUrl(mailbox, RedirectionCallback);

        private bool RedirectionCallback(string url)
        {
            return true; 
        }

我也尝试将URL设置为以下

service.Url = new Uri("https://autodiscover.MYDOMAIN.com/autodiscover/autodiscover.xml");
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");

这些都没有解决问题。有人知道从这里去哪里吗?

1 个答案:

答案 0 :(得分:0)

  • service.UseDefaultCredentials应该为false,因为您需要使用电子邮件+密码(作为安全字符串)进行连接
  • 使用最新的ExchangeVersion值
  • URL为https://outlook.office365.com/EWS/Exchange.asmx

    public ExchangeService Connect()
    {
        var lastExchangeVersion = Enum.GetValues(typeof(ExchangeVersion)).Cast<ExchangeVersion>().ToList().Last();
        var service = new ExchangeService(lastExchangeVersion)
        {
            Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx"),
            Credentials = new NetworkCredential(_cloudEmail, _cloudPassword)
        };
        return service;
    }
    public SecureString ConvertStringToSecure(string password)
    {
        if (string.IsNullOrWhiteSpace(password)) return null;
        var result = new SecureString();
        foreach (char c in password) result.AppendChar(c);
        return result;
    }