关于Office 365的EWS Web服务

时间:2015-07-17 09:30:00

标签: c#

我正在使用EWS网络服务从Office 365帐户中获取电子邮件。 我收到此错误

  

无法找到自动发现服务。

我已经写了这段代码。

ExchangeService service = new ExchangeService(userData.Version);

if (listener != null)
{
    service.TraceListener = listener;
    service.TraceFlags = TraceFlags.All;
    service.TraceEnabled = true;
}

service.Credentials = new NetworkCredential(userData.EmailAddress, userData.Password);
service.UseDefaultCredentials = false;

if (userData.AutodiscoverUrl == null)
{
    Console.Write(string.Format("Using Autodiscover to find EWS URL for {0}. Please wait... ", userData.EmailAddress));

    service.AutodiscoverUrl(userData.EmailAddress);
    userData.AutodiscoverUrl = service.Url;

    Console.WriteLine("Complete");
}

请检查我做错了什么。 感谢

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

ExchangeService service = new ExchangeService();
service.TraceEnabled = true;
service.Credentials = new WebCredentials(User, Pwd);
service.AutodiscoverUrl(User, RedirectionUrlValidationCallback);
service.TraceEnabled = true;