【发布时间】:2011-12-04 22:11:03
【问题描述】:
在我们的组织中,我们正在尝试使用 EWS 托管 API 从 Exchange 2010 上的自定义 UI 客户端访问邮箱。我们有一个在 IIS 7.5 上运行的 .NET 4.0 WCF 服务,代表 UI 客户端调用 EWS 方法。客户端和 WCF 服务通过 https 进行通信,WCF 服务和 EWS 也是如此。我们现在要创建服务帐户(基本上是在某些电子邮件收件箱上具有模拟权限的 AD 帐户)并在这些服务帐户下运行 WCF 服务。但是,当我在 IIS 中的特定 AD 用户下运行 WCF 服务(启用匿名身份验证并设置为特定 AD 用户的匿名用户身份)时,EWS 会引发 401 Unauthorized 异常。检查 ExchangeService 对象后,Credentials 对象为空。如果我对凭据进行硬编码,则该服务可以访问 EWS。下面是我用来创建 ExchangeService 对象的代码。
var service = new ExchangeService(ExchangeVersion.Exchange2010)
{
Url = new Uri(ConfigurationManager.AppSettings["EWSUrl"]),
// If I uncomment the below line, the service can access EWS. However, I want the user under which the service is running to access EWS.
//Credentials = new NetworkCredential("ImpersonatingUser", "secretPwd", "TESTDOMAIN"),
ImpersonatedUserId = new ImpersonatedUserId { Id = emailAddress, IdType = ConnectingIdType.SmtpAddress },
};
我在某处读到 System.ServiceModel.ServiceSecurityContext.Current.WindowsIdentity 对象将拥有运行服务的当前用户。但是,在我的情况下,System.ServiceModel.ServiceSecurityContext.Current 上下文为空。
如何获取服务帐户的凭据(无需在代码中硬编码)并将其传递给 EWS?如果您需要更多详细信息,请告诉我。
编辑:在 IIS 7.5 中,我创建了一个以模拟 AD 用户身份运行的单独应用程序池,并将我的 WCF 服务配置为在此应用程序池中运行。仍然无法获取服务凭据。
提前致谢。
【问题讨论】:
标签: wcf impersonation exchangewebservices