确定要模拟的帐户Identify the account to impersonate

了解您的服务应用程序如何使用 EWS 来标识要模拟的用户。Learn how your service application uses EWS to identify the user to impersonate.

您的服务应用程序通过使用以下三个标识符之一来标识要模拟的用户帐户:Your service application identifies the user account to impersonate by using one of the following three identifiers:

  • 主 SMTP 地址。The primary SMTP address.

  • 用户主体名称(UPN)。The user principal name (UPN).

  • 安全标识符(SID)。The security identifier (SID).

您使用的标识符取决于您的应用程序提供的信息。The identifier that you use depends, of course, on the information that your application has available.

标识要模拟的用户帐户Identifying the user account to impersonate

您的应用程序可以使用 EWS 托管 API 或 EWS SOAP 请求来标识正在模拟的用户帐户。Your application can use either the EWS Managed API or EWS SOAP requests to identify the user account that it is impersonating. EWS 托管 API 使用ExchangeService属性来标识模拟的用户。The EWS Managed API uses the ExchangeService.ImpersonatedUserId property to identify the impersonated user. EWS 使用ExchangeImpersonation元素,如以下 XML 片段所示。EWS uses the ExchangeImpersonation element, as shown in the following XML fragment.

<soap:Header>
    <t:ExchangeImpersonation>
        <t:ConnectingSID>
            Identifier
        </t:ConnectingSID>
    </t:ExchangeImpersonation>
</soap:Header>

以下各节显示了如何使用其中一个标识符。Each of the following sections shows how to use one of the identifiers. 有关在操作中显示模拟标识符的示例,请参阅使用 Exchange 模拟添加约会For an example that shows the impersonation identifier in action, see Add appointments by using Exchange impersonation.

使用 SMTP 电子邮件地址标识用户帐户Use the SMTP email address to identify the user account

SMTP 电子邮件地址是与用户帐户相关联的主电子邮件地址。The SMTP email address is the primary email address that is associated with a user account.

在 EWS 托管 API 应用程序中,您可以指定 SMTP 电子邮件地址和ConnectingIdType枚举值。In an EWS Managed API application, you specify the SMTP email address along with the ConnectingIdType.SMTP enumeration value.

exchangeServiceInstance.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SMTP, "alisa@contoso.com");

在 EWS SOAP 请求中, PrimarySmtpAddress元素包含用户帐户的电子邮件地址。In an EWS SOAP request, the PrimarySmtpAddress element contains the email address for the user account.

<soap:Header>
  <t:ExchangeImpersonation>
    <t:ConnectingSID>
      <t:PrimarySmtpAddress>alisa@contoso.com</t: PrimarySmtpAddress>
    </t:ConnectingSID>
  </t:ExchangeImpersonation>
</soap:Header>

使用 UPN 标识用户帐户Use the UPN to identify the user account

UPN 包含用户帐户位置的完全限定的域名(FQDN)。The UPN contains the fully qualified domain name (FQDN) for the location of the user account. 这不一定是用户的邮箱域。This is not necessarily the user's mailbox domain. 必须在 Active Directory 域服务(AD DS)中的用户帐户上正确设置UserPrincipalName属性,才能成功实现用户查找。The UserPrincipalName attribute must be set correctly on the user account in Active Directory Domain Services (AD DS) for the user lookup to succeed.

在 EWS 托管 API 应用程序中,您可以指定 UPN 以及ConnectingIdType枚举值。In an EWS Managed API application, you specify the UPN along with the ConnectingIdType.PrincipalName enumeration value.

exchangeServiceInstance.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, "alias@billing.contoso.com");

在 EWS SOAP 请求中, PrincipalName 元素(ConnectingSIDType 复杂类型)(EWS)元素包含用户帐户的 UPN。In an EWS SOAP request, the PrincipalName element (ConnectingSIDType complexType) (EWS) element contains the UPN for the user account.

<soap:Header>
  <t:ExchangeImpersonation>
    <t:ConnectingSID>
      <t:PrincipalName>alisa@billing.contoso.com</t:PrincipalName>
    </t:ConnectingSID>
  </t:ExchangeImpersonation>
</soap:Header>

使用 SID 标识用户帐户Use the SID to identify the user account

SID 是要以安全描述符定义语言(SDDL)形式模拟的帐户的标识符。The SID is the identifier of the account to be impersonated in security descriptor definition language (SDDL) form.

在 EWS 托管 API 应用程序中,您可以指定 SID 以及ConnectingIdType枚举值。In an EWS Managed API application, you specify the SID along with the ConnectingIdType.SID enumeration value.

exchangeServiceInstance.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SID, "S-1-5-21-1493619105-1843311271-3936346804-1118");

在 EWS SOAP 请求中, sid元素包含用户帐户的 sid。In an EWS SOAP request, the SID element contains the SID for the user account.

<soap:Header>
  <t:ExchangeImpersonation>
    <t:ConnectingSID>
      <t:SID>S-1-5-21-1493619105-1843311271-3936346804-1118</t:SID>
    </t:ConnectingSID>
  </t:ExchangeImpersonation>
</soap:Header>

另请参阅See also