使用EWS Managed API 進行郵件收取
提示為AutodiscoverUrl處異常, The Autodiscover service couldn't be located 。
在xp x86本地開發環境下代碼沒有問題,放到win2008x64上時報錯,說明與程序運行環境有關。
查閱官方文檔:Getting Started with the EWS Managed API 可得知,ssl可導致這個錯誤出現。
可根據官方文檔添加以下代碼:
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
// Hook up the cert callback.
System.Net.ServicePointManager.ServerCertificateValidationCallback =
delegate(
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors)
{
// Validate the certificate and return true or false as appropriate.
// Note that it not a good practice to always return true because not
// all certificates should be trusted.
};
另,一網友也碰到了此問題,並附有解決方法:http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/bdc45cd8-6385-4900-9e40-23814beb7639?Thread%3Abdc45cd8-6385-4900-9e40-23814beb7639=Microsoft.Forums.Data.Models.Discussion&ThreadViewModel%3Abdc45cd8-6385-4900-9e40-23814beb7639=Microsoft.Forums.CachedViewModels.ThreadViewModel