使用自动发现刷新配置信息Refresh configuration information by using Autodiscover

了解如何以及何时使用自动发现刷新 Exchange 连接的配置信息。Learn how and when to refresh configuration information for your Exchange connection by using Autodiscover.

当您的 EWS 应用程序第一次运行时,自动发现为您收集所需的信息以连接到用户的 Exchange 邮箱提供了一种非常好的方法。When your EWS application runs for the first time, Autodiscover provides a great way for you to collect the information you need in order to connect to your user's Exchange mailbox. 但自动发现并不仅用于首次使用。But Autodiscover isn't just for first time use. 定期使用自动发现有助于让应用程序对 Exchange 部署中的更改做出响应,从而帮助保持应用程序的连接。Using Autodiscover on a regular basis can help keep your application connected by enabling it to respond to changes in the Exchange deployment.

缓存自动发现终结点和 EWS 设置Cache Autodiscover endpoint and EWS settings

尽管我们建议您定期使用自动发现,但在使用它时需要考虑一些事项。While we recommend that you use Autodiscover regularly, how regularly you use it requires some consideration. 理想情况下,您可以对环境中的更改进行快速平衡,以生成不必要的网络通信。Ideally you can balance responding quickly to changes in the environment against generating too much unnecessary network traffic. 当应用程序首次获得成功的自动发现响应时,应保存以下信息,以便在每次发送 EWS 请求时无需重复自动发现过程。When your application gets a successful Autodiscover response for the first time, you should save the following information so that you do not have to repeat the Autodiscover process every time you send an EWS request.

表1。用于自动发现请求的缓存信息Table 1. Information to cache for Autodiscover requests

设置为缓存Setting to cache 有效期为 .。。Valid for… 详细信息Details
自动发现终结点Autodiscover endpoint
只要工作正常As long as it works
如果保存返回成功响应的自动发现终结点,则无需重复生成自动发现终结点列表的过程,并在收到成功的响应之前尝试这些终结点。When you save the Autodiscover endpoint that returned a successful response, you do not have to repeat the process of generating a list of Autodiscover endpoints and trying them until you get a successful response.

注意: EWS 托管 API 不支持缓存自动发现终结点。NOTE: The EWS Managed API does not support caching the Autodiscover endpoint.
EWS URL 和从自动发现响应中检索到的任何其他设置EWS URL and any other settings retrieved from the Autodiscover response
一周One week
通过保存 EWS URL 和其他相关设置,您无需为每个 EWS 请求发送新的自动发现请求,或者如果您的应用程序重新启动。By saving the EWS URL and other related settings, you do not have to send a new Autodiscover request for each EWS request or if your application restarts. 但是,即使 EWS URL 适用于你的用户,服务器的可用性也可能更佳。However, even if an EWS URL works for your user, a server might be available that is more optimal.

例如,用户的邮箱可能已移动到新的邮箱服务器,从而导致新的首选 EWS 终结点。For example, the user's mailbox might have moved to a new mailbox server, resulting in a new preferred EWS endpoint. 我们建议您在一周后通过发送新的自动发现请求来刷新您的用户设置(自上次的自动发现请求后)。We recommend that you refresh your user settings by sending a new Autodiscover request after one week has passed since your last Autodiscover request. 可以对此时间进行调整,以满足应用程序的要求。This time can be adjusted to meet the requirements of your application.

刷新缓存的配置信息Refresh cached configuration information

现在您已缓存了信息,我们来看看如何将缓存保持最新。Now that you have the information cached, let's examine how you can keep that cache fresh. 我们建议您在以下情况中刷新缓存的信息:We recommend that you refresh your cached information when:

  • 信息的有效期已过期。The information's validity period expires.

  • 将发生与连接相关的错误,并且缓存的信息在一小时前进行刷新。A Connection-related error occurs AND your cached information was last refreshed over an hour ago.

若要刷新缓存的信息,请向缓存的自动发现终结点发送自动发现请求,并执行以下操作:To refresh your cached information, send an Autodiscover request to a cached Autodiscover endpoint, and do the following:

  • 如果请求成功,请将响应中的 EWS 终结点与缓存的 EWS 终结点进行比较,并执行以下操作:If the request succeeds, compare the EWS endpoint in the response with the cached EWS endpoint, and do the following:

    • 如果它们不同,则使用新的 EWS 终结点。If they are different, use the new EWS endpoint. 如果要刷新以从错误中恢复,请使用新终结点重试失败的请求。If you're refreshing to recover from an error, retry the failed request with the new endpoint.

    • 如果它们相同,则继续使用原始 EWS 终结点。If they are the same, continue to use the original EWS endpoint. 如果要刷新以从错误中恢复,请根据需要处理错误。If you're refreshing to recover from an error, handle the error as appropriate.

  • 如果请求失败,则从头开始启动自动发现过程If the request fails, start the Autodiscover process from the beginning. 在收到成功的响应之后,将缓存的自动发现终结点替换为成功的自动发现终结点,并继续使用新的 EWS 终结点。After you get a successful response, replace the cached Autodiscover endpoint with the Autodiscover endpoint that succeeded and continue to use the new EWS endpoint. 如果未收到成功的响应,请继续使用原始自动发现终结点和 EWS 终结点。If you do not get a successful response, continue to use the original Autodiscover endpoint and EWS endpoint. 如果要刷新以从错误中恢复,请根据需要处理错误。If you're refreshing to recover from an error, handle the error as appropriate.

下图提供了此过程的直观表示形式。The following figure provides a visual representation of this process.

图1。使用自动发现刷新配置信息的过程Figure 1. Process for refreshing configuration information by using Autodiscover

此示意图说明自动发现如何刷新配置信息。

刷新缓存的配置信息有助于解决一些错误,但并非全部。Refreshing your cached configuration information can help with some errors, but not all.

表2。通过刷新缓存解决的错误Table 2. Errors addressed by refreshing your cache

ErrorError EWS 托管 API 实现EWS Managed API implementation 备注Notes
DNS 或网络故障错误DNS or network failure errors

示例:找不到主机名。Example: Host name could not be found.
ServiceRemoteExceptionServiceRemoteException
指示找不到或无法达到服务器的任何错误都可能通过尝试自动发现来解决。Any error that indicates that the server could not be found or could not be reached might be resolved by trying Autodiscover.

缓存的 EWS 终结点可能不再有效,并且自动发现可能会指向新服务器。Your cached EWS endpoint might no longer be valid, and Autodiscover might be able to point you to the new server.
HTTP 状态错误HTTP status errors

示例:503服务不可用Example: 503 Service Unavailable
ServiceRemoteExceptionServiceRemoteException
HTTP 状态错误可能因多种原因而发生。HTTP status errors can happen for many different reasons.

但是,最好尝试使用自动发现以查看是否有新的 EWS 终结点可供用户使用。However, it's a good idea to try Autodiscover to see if a new EWS endpoint is available for the user.
EWS 错误代码EWS error codes

示例: ErrorConnectionFailedExample: ErrorConnectionFailed
ResponseCodeTypeResponseCodeType
大多数 EWS 错误代码不一定会刷新您的配置信息。Most EWS error codes don't warrant refreshing your configuration information.

但是,以下内容特别指出需要更新配置信息:However, the following specifically indicate that the configuration information needs to be updated:
- ErrorConnectionFailed- ErrorConnectionFailed
- ErrorMailboxMoveInProgress- ErrorMailboxMoveInProgress

另请参阅See also