Azure Webjob:C# - 无法找到自动发现服务错误
Azure Webjob: C# - The Autodiscover service couldn't be located error
我正在将 C# 控制台应用程序作为 Azure Webjob 上传。我得到的错误是:
Unhandled Exception:
Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: The
Autodiscover service couldn't be located.
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String
emailAddress, List1 redirectionEmailAddresses, Int32& currentHop)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetLegacyUserSettings[TSettings](String
emailAddress)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String
emailAddress, List`1 requestedSettings)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String
userSmtpAddress, UserSettingName[] userSettingNames)
at Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String
emailAddress, ExchangeVersion requestedServerVersion,
AutodiscoverRedirectionUrlValidationCallback
validateRedirectionUrlCallback)
at
Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String
emailAddress, AutodiscoverRedirectionUrlValidationCallback
validateRedirectionUrlCallback)
这是我的代码:
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
// The default for the validation callback is to reject the URL.
bool result = false;
Uri redirectionUri = new Uri(redirectionUrl);
// Validate the contents of the redirection URL. In this simple validation
// callback, the redirection URL is considered valid if it is using HTTPS
// to encrypt the authentication credentials.
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}
static void Main(string[] args)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials("email@mySite.com", "myPassword", "mysite.com");
service.AutodiscoverUrl("email@mySite.com", RedirectionUrlValidationCallback);
// More irrelevant code here
}
上面的代码取自这个问题作为已接受的答案:
运行 这段代码在我的机器上作为控制台应用程序运行得很好。但这作为网络作业出错了,有人可以帮忙吗?
我用我的 Office 365 帐户测试了您的代码,它在我这边运行良好。我还使用 Console.WriteLine 打印出 return URL 和服务 URL。这是我在 WebJob 仪表板中看到的内容。
[05/24/2017 05:54:52 > 7adbf1: SYS INFO] Run script 'TestO365WebJob.exe' with script host - 'WindowsScriptHost'
[05/24/2017 05:54:52 > 7adbf1: SYS INFO] Status changed to Running
[05/24/2017 05:54:59 > 7adbf1: INFO] return URL: https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml
[05/24/2017 05:55:00 > 7adbf1: INFO] Service URL https://outlook.office365.com/EWS/Exchange.asmx
请仔细检查您的用户名和密码。他们是对的吗?您的密码是否已过期?
要获取失败原因的详细信息,我们可以在您的网络应用程序诊断日志面板上打开应用程序日志并将 TraceEnabled 属性 设置为 true。我们可以通过查看应用程序跟踪日志来了解问题所在。
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.TraceEnabled = true;
此外,由于Office365中只有一个EWS端点。我们可以直接设置服务 URL 而不是使用自动发现。以下代码供您参考。
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials("user@domain.onmicrosoft.com", "password", "domain.onmicrosoft.com");
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
我正在将 C# 控制台应用程序作为 Azure Webjob 上传。我得到的错误是:
Unhandled Exception: Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: The Autodiscover service couldn't be located.
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String emailAddress, List1 redirectionEmailAddresses, Int32& currentHop)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetLegacyUserSettings[TSettings](String emailAddress)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress, List`1 requestedSettings)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames)
at Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
at Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
这是我的代码:
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
// The default for the validation callback is to reject the URL.
bool result = false;
Uri redirectionUri = new Uri(redirectionUrl);
// Validate the contents of the redirection URL. In this simple validation
// callback, the redirection URL is considered valid if it is using HTTPS
// to encrypt the authentication credentials.
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}
static void Main(string[] args)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials("email@mySite.com", "myPassword", "mysite.com");
service.AutodiscoverUrl("email@mySite.com", RedirectionUrlValidationCallback);
// More irrelevant code here
}
上面的代码取自这个问题作为已接受的答案:
运行 这段代码在我的机器上作为控制台应用程序运行得很好。但这作为网络作业出错了,有人可以帮忙吗?
我用我的 Office 365 帐户测试了您的代码,它在我这边运行良好。我还使用 Console.WriteLine 打印出 return URL 和服务 URL。这是我在 WebJob 仪表板中看到的内容。
[05/24/2017 05:54:52 > 7adbf1: SYS INFO] Run script 'TestO365WebJob.exe' with script host - 'WindowsScriptHost'
[05/24/2017 05:54:52 > 7adbf1: SYS INFO] Status changed to Running
[05/24/2017 05:54:59 > 7adbf1: INFO] return URL: https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml
[05/24/2017 05:55:00 > 7adbf1: INFO] Service URL https://outlook.office365.com/EWS/Exchange.asmx
请仔细检查您的用户名和密码。他们是对的吗?您的密码是否已过期?
要获取失败原因的详细信息,我们可以在您的网络应用程序诊断日志面板上打开应用程序日志并将 TraceEnabled 属性 设置为 true。我们可以通过查看应用程序跟踪日志来了解问题所在。
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.TraceEnabled = true;
此外,由于Office365中只有一个EWS端点。我们可以直接设置服务 URL 而不是使用自动发现。以下代码供您参考。
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials("user@domain.onmicrosoft.com", "password", "domain.onmicrosoft.com");
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");