在 Exchange 中使用 EWS 获取服务配置信息

了解如何从 Exchange 中的 EWS 获取 UM、策略微移、邮件提示和保护规则的服务配置信息。

EWS 应用程序是否适用于统一消息 (UM) 、策略微移、邮件提示或保护规则? 如果是这样,应用程序需要调用 GetServiceConfiguration 操作 来获取所需的服务配置信息。 GetServiceConfiguration 操作返回特定于每个 EWS 功能的配置信息。

注意

EWS 托管 API 无法实现此功能。

表 1. GetServiceConfiguration 操作返回的配置信息

EWS 功能 GetServiceConfiguration 操作返回...
UM
  • 一个值,该值指示是否启用 UM。
  • 一个值,该值指示是否启用在手机上玩游戏。
  • 在电话拨号字符串上播放。
策略微移
  • 在客户端中显示的策略微移。
邮件提示
  • 一个值,该值指示是否启用邮件提示。
  • 每个请求的最大收件人数。
  • 最大消息大小。
  • 大型受众阈值。
  • 一个 值,该值指示是否显示外部收件人的数量。
  • 内部域的列表。
  • 一个值,该值指示是否启用策略提示。
  • 指示邮件是否被视为包含大量收件人的大型受众上限阈值。
保护规则
  • 客户端的保护规则设置。
  • 组织内部域的列表。

代码示例:使用 EWS 获取邮件提示的服务配置信息

下面的代码示例使用 GetServiceConfiguration 操作 请求邮件提示的服务配置信息。 可以通过添加具有不同值的更多 ConfigurationName 元素来请求其他服务配置信息。

private static void GetServiceConfiguration(ExchangeService service, NetworkCredential creds)
{ 
  // XML for the GetServiceConfiguration request SOAP envelope for mail tips configuration information.
  const string getServiceConfigurationRequest = 
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
    "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
    "               xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\"\n" +
    "               xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\" \n" +
    "               xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
    "               xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
    "  <soap:Header>\n" +
    "    <t:RequestServerVersion Version=\"Exchange2013\" />\n" +
    "  </soap:Header>\n" +
    "  <soap:Body>\n" +
    "    <m:GetServiceConfiguration>\n" +
    "      <m:ActingAs>\n" +
    "        <t:EmailAddress>user1@contoso.com</t:EmailAddress>\n" +
    "        <t:RoutingType>SMTP</t:RoutingType>\n" +
    "      </m:ActingAs>\n" +
    "      <m:RequestedConfiguration>\n" +
    "        <m:ConfigurationName>MailTips</m:ConfigurationName>\n" +
    "      </m:RequestedConfiguration>\n" +
    "    </m:GetServiceConfiguration>\n" +
    "  </soap:Body>\n" +
    "</soap:Envelope>";
  // Encoded GetServiceConfiguration operation request.
  byte[] payload = System.Text.Encoding.UTF8.GetBytes(getServiceConfigurationRequest);
  try
  {
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(service.Url);
    request.AllowAutoRedirect = false;
    request.Credentials = creds;
    request.Method = "POST";
    request.ContentType = "text/xml";
    Stream requestStream = request.GetRequestStream();
    requestStream.Write(payload, 0, payload.Length);
    requestStream.Close();
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    if (response.StatusCode == HttpStatusCode.OK)
    {
      Stream responseStream = response.GetResponseStream();
      StreamReader reader = new StreamReader(responseStream);
      string responseFromServer = reader.ReadToEnd();
      Console.WriteLine("You will need to parse this response to get the configuration information:\n\n" + responseFromServer);
      reader.Close();
      responseStream.Close();
    }
    else
      throw new WebException(response.StatusDescription);
          
  }
  catch (WebException e)
  {
    Console.WriteLine(e.Message);
  }
}

后续步骤

请求服务配置信息后,使用 XmlDocument 类 加载响应 XML,以便可以对其进行分析。 然后,根据你的方案,你可以执行以下操作之一:

另请参阅