使用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