/ 中存储网

提醒大家注意Exchange2010 Ews 调用的时候需要注意到事项

2014-08-28 23:31:54 来源:中存储网
 第一:在调用的时候需要(2010 采用的是SSL加密的形式,所以我们调用的时候需要加上如下的代码,)

以下是代码片段:
    ExchangeVersion RequestedServerVersion = config.ExchangeVersion == "2007" ?    ExchangeVersion.Exchange2007_SP1 : ExchangeVersion.Exchange2010;
  System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
  service = new ExchangeService(RequestedServerVersion)
  {
  Url = new Uri(config.EWSServiceUrl),
  Credentials = new NetworkCredential(config.ExchangeAdministrator,
  config.ExchangeAdministratorPassword,
  config.Domain),
  };

以下是代码片段:
    public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
  {
  public TrustAllCertificatePolicy()
  { }
  public bool CheckValidationResult(ServicePoint sp,
  System.Security.Cryptography.X509Certificates.X509Certificate cert,
  WebRequest req, int problem)
  {
  return true;
  }
  }

关键是如下句:

以下是代码片段:
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();

第二:打开Exchange 2010 服务器在命令行中输入

以下是代码片段:
New-ManagementRoleAssignment -Name:impersonationAssignmentName -Role:ApplicationImpersonation -User:serviceAccount

serviceAccount:就是我们要模拟其他人的账户