路由公用文件夹层次结构请求

需要了解公用文件夹层次结构(例如移动、更新、删除或查找公用文件夹)的所有公用文件夹信息请求都需要路由到给定用户的默认公用文件夹层次结构邮箱。 若要将请求路由到该邮箱,需要将 X-AnchorMailboxX-PublicFolderMailbox 标头设置为自动发现服务返回的特定值。

公用文件夹概述

标头 我需要什么? 如何实现明白吗?
X-AnchorMailbox
GetUserSettings 自动发现 SOAP 响应中的 PublicFolderInformation 值,该响应成为 X-AnchorMailbox 标头的值。 1. 使用用户邮箱的 SMTP 地址发送 GetUserSetting 请求。

2. 使用 PublicFolderInformation 元素填充 X-AnchorMailbox 标头的值。 PublicFolderInformation 元素的值是 SMTP 地址。
X-PublicFolderMailbox
来自 GetUserSettings 自动发现 SOAP 响应的 InternalRpcClientServer 值,该响应成为 X-PublicFolderMailbox 标头的值。 1. 使用用户邮箱的 SMTP 地址发送 GetUserSetting 请求。

2. 使用自动发现服务返回的 InternalRpcClientServer 元素填充 X-PublicFolderMailbox 标头的值。 X-PublicFolderMailbox 元素的值是 SMTP 地址,其中该地址的用户部分是 GUID。

确定标头值后, 在发出公用文件夹层次结构请求时包括它们。

本文中的步骤特定于公用文件夹层次结构请求。 若要确定请求是公用文件夹层次结构还是内容请求,请参阅 路由公用文件夹请求

使用 EWS 托管 API 确定标头值

可以使用以下代码对 GetUserSettings 进行单个调用,该代码将同时检索 InternalRpcClientServerPublicFolderInformation 元素。 将邮箱用户的 SMTP 地址作为输入参数包含在内。

GetUserSettingsResponse userResponse = GetUserSettings(adservice, "sonyaf@contoso.com", 3, UserSettingName.PublicFolderInformation, UserSettingName.InternalRpcClientServer);
Console.WriteLine("X-AnchorMailbox value for public folder hierarchy requests: {0}", userResponse.Settings[UserSettingName.PublicFolderInformation]);
Console.WriteLine("X-PublicFolderMailbox value for public folder hierarchy requests: {0}", userResponse.Settings[UserSettingName.InternalRpcClientServer]);

运行代码后,控制台上会显示以下信息:

X-AnchorMailbox for public folder hierarchy requests: SharedPublicFolder@contoso.com
X-PublicFolderMailbox value for public folder hierarchy requests: 1ec2a236-ed93-4f88-b9c6-33e63fa4aa44@contoso.com

现在,你已具有 PublicFolderInformation 值,请将其作为所有公用文件夹层次结构请求中的 X-AnchorMailbox 标头的值包含在内。 InternalRpcClientServer 值用于 X-PublicFolderMailbox 标头。 这两个标头是必需的。

X-AnchorMailbox: SharedPublicFolder@contoso.com
X-PublicFolderMailbox: 1ec2a236-ed93-4f88-b9c6-33e63fa4aa44@contoso.com

使用 SOAP 确定标头值

下面的代码示例演示如何使用 GetUserSettings SOAP 操作检索 PublicFolderInformationInternalRpcClientServer 值。 邮箱用户是在 Mailbox 元素中指定的, RequestedSettings 元素将响应限制为 PublicFolderInformationInternalRpcClientServer 值。

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:a="http://schemas.microsoft.com/exchange/2010/Autodiscover"
               xmlns:wsa="http://www.w3.org/2005/08/addressing"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <a:RequestedServerVersion>Exchange2016</a:RequestedServerVersion>
    <wsa:Action>http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetUserSettings</wsa:Action>
    <wsa:To>https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc</wsa:To>
  </soap:Header>
  <soap:Body>
    <a:GetUserSettingsRequestMessage xmlns:a="http://schemas.microsoft.com/exchange/2010/Autodiscover">
      <a:Request>
        <a:Users>
          <a:User>
            <a:Mailbox>sonyaf@contoso.com</a:Mailbox>
          </a:User>
        </a:Users>
        <a:RequestedSettings>
          <a:Setting>PublicFolderInformation</a:Setting>
          <a:Setting>InternalRpcClientServer</a:Setting>
        </a:RequestedSettings>
      </a:Request>
    </a:GetUserSettingsRequestMessage>
  </soap:Body>
</soap:Envelope>

响应包括 PublicFolderInformation 值。

<UserSetting i:type="StringSetting">
  <Name>InternalRpcClientServer</Name>
  <Value>1ec2a236-ed93-4f88-b9c6-33e63fa4aa44@contoso.com</Value>
</UserSetting>
<UserSetting i:type="StringSetting">
    <Name>PublicFolderInformation</Name>
    <Value>SharedPublicFolder@contoso.com</Value>
</UserSetting>

现在,你已具有 PublicFolderInformation 值,请将其作为所有公用文件夹层次结构请求中的 X-AnchorMailbox 标头的值包含在内。 对 X-PublicFolderMailbox 标头使用 InternalRpcClientServer 值。 这两个标头是必需的。

X-AnchorMailbox: SharedPublicFolder@contoso.com
X-PublicFolderMailbox: 1ec2a236-ed93-4f88-b9c6-33e63fa4aa44@contoso.com

有关自动发现过程的详细信息,请参阅 自动发现 for Exchange生成自动发现终结点列表和使用 自动发现从 Exchange 获取用户设置

设置 X-AnchorMailbox 和 X-PublicFolderMailbox 标头的值

使用使用 EWS 托管 API 确定 X-AnchorMailbox 标头的值或使用 SOAP 确定 X-AnchorMailbox 标头的值中获取PublicFolderInformationInternalRpcClientServer 的值,设置公用文件夹内容请求中的 X-AnchorMailboxX-PublicFolderMailbox 标头的值。

例如,给定 PublicFolderInformation SMTP 地址 SharedPublicFolder@contoso.com 和 InternalRpcClientServer 值 1ec2a236-ed93-4f88-b9c6-33e63fa4aa44@contoso.com,在调用以下方法或操作时包括以下标头。

X-AnchorMailbox: SharedPublicFolder@contoso.com
X-PublicFolderMailbox: 1ec2a236-ed93-4f88-b9c6-33e63fa4aa44@contoso.com

需要 X-AnchorMailbox 和 X-PublicFolder 标头的公用文件夹调用

EWS 托管 API EWS 操作
Folder.FindFolders
Folder.Delete
Folder.Update
Folder.Move
CreateFolder
FindFolder
DeleteFolder
UpdateFolder
MoveFolder

若要使用 EWS 托管 API 添加这些标头,请使用 HttpHeaders.Add 方法。

service.HttpHeaders.Add("X-AnchorMailbox", "SharedPublicFolder@contoso.com");
service.HttpHeaders.Add("X-PublicFolderMailbox", "1ec2a236-ed93-4f88-b9c6-33e63fa4aa44@contoso.com");

例如,以下代码显示了 一个 FindFolder 请求,其中 X-AnchorMailboxX-PublicFolderMailbox 标头设置为本文示例中检索的值。

POST https://outlook.office365.com/EWS/Exchange.asmx HTTP/1.1
Content-Type: text/xml; charset=utf-8
X-AnchorMailbox: SharedPublicFolder@contoso.com
X-PublicFolderMailbox: 1ec2a236-ed93-4f88-b9c6-33e63fa4aa44@contoso.com
Host: outlook.office365.com
Content-Length: 1174
Expect: 100-continue
Connection: Keep-Alive
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2013_SP1" />
  </soap:Header>
  <soap:Body>
    <m:FindFolder Traversal="Shallow">
      <m:FolderShape>
        <t:BaseShape>AllProperties</t:BaseShape>
      </m:FolderShape>
      <m:IndexedPageFolderView MaxEntriesReturned="1" Offset="0" BasePoint="Beginning" />
      <m:Restriction>
        <t:IsEqualTo>
          <t:FieldURI FieldURI="folder:DisplayName" />
          <t:FieldURIOrConstant>
            <t:Constant Value="My Public Contacts" />
          </t:FieldURIOrConstant>
        </t:IsEqualTo>
      </m:Restriction>
      <m:ParentFolderIds>
        <t:FolderId Id="AQEuAAADy/LIWjRCp0GFb0W6aGPbwwEARg5aCLUc8k6wLfl1c0a/2AAAAwIAAAA=" ChangeKey="AQAAABYAAABGDloItRzyTrAt+XVzRr/YAABdo/XB" />
      </m:ParentFolderIds>
    </m:FindFolder>
  </soap:Body>
</soap:Envelope>

另请参阅