使用 EWS 托管 API 设置 EWS 服务 URL

查找有关如何在 EMS 托管 API 应用程序中设置 EWS 服务 URL 的信息。

服务 URL 是 Exchange 用于与 Exchange Web Services (EWS) 通信的地址。 当您的 EWS Managed API 应用程序具有此地址,并且有相应的权限与 EWS 通信后,即可调用 ExchangeService 类。 内部部署 Exchange 服务器的服务 URL 可能如下所示。

https://computer.domain.contoso.com/EWS/Exchange.asmx

您可以通过多种方式在应用程序中设置 EWS URL。 我们建议使用自动发现服务获取 URL,因为在大量服务器中,如果邮箱迁移到另一台服务器,URL 可能会更改。 但是,因为调用自动发现可能需要一段时间,并且如果您需要在短时间内进行多次调用,可能会减缓您的应用程序的速度,您可能需要缓存从自动发现获取的 URL 值并使用此缓存值手动设置 EWS 服务 URL。 这将改进应用程序的性能,只需确保当服务器上的值发生变更时使用自动发现定期更新您的缓存值即可。

使用自动发现服务设置 EWS 服务 URL

AutodiscoverUrl 方法使用电子邮件地址设置 ExchangeService 终结点,并使您的应用程序可以使用 ExchangeService 代理类中包含的任何方法。 以下示例显示如何使用 AutodiscoverURL 方法。

// Create the binding.
ExchangeService service = new ExchangeService();
// Set the credentials for the on-premises server.
service.Credentials = new WebCredentials("user1@contoso.com", "password");
// Set the URL.
service.AutodiscoverUrl("User1@contoso.com");

手动设置 Exchange 服务 URL

以下示例显示如何使用缓存值设置 EWS 服务 URL。 在执行此操作之前,确保使用自动发现服务获取 EWS URL。

// Create the binding.
ExchangeService service = new ExchangeService();
// Set the credentials for the on-premises server.
service.Credentials = new WebCredentials("user1@contoso.com", "password");
// Set the URL.
service.Url = new Uri("https://computername.domain.contoso.com/EWS/Exchange.asmx");

另请参阅