Поделиться через


Using Autodiscover to get user settings

Last modified: December 10, 2012

Applies to: EWS Managed API | Exchange Server 2010

Note: This content applies to the EWS Managed API 2.0 and earlier versions. For the latest information about the EWS Managed API, see Web services in Exchange.

You can use the Microsoft Exchange Web Services (EWS) Managed API to obtain the configuration settings for a user. The Autodiscover service returns only the configuration settings requested. If a requested setting is not implemented on the Exchange server, no element is returned.

The following table lists the possible user configuration settings that can be returned.

Configuration setting name

Description

UserDisplayName

The display name of the user.

UserDN

The legacy distinguished name of the user.

UserDeploymentId

The deployment identifier of the user.

InternalMailboxServer

The fully qualified domain name (FQDN) of the mailbox server.

InternalRpcClientServer

The FQDN of the RPC client server.

InternalMailboxServerDN

The legacy distinguished name of the mailbox server.

InternalEcpUrl

The internal URL of the Exchange Control Panel.

InternalEcpVoicemailUrl

The internal URL of the Exchange Control Panel for voice-mail customization.

InternalEcpEmailSubscriptionsUrl

The internal URL of the Exchange Control Panel for e-mail subscriptions.

InternalEcpTextMessagingUrl

The internal URL of the Exchange Control Panel for text messaging.

InternalEcpDeliveryReportUrl

The internal URL of the Exchange Control Panel for delivery reports.

InternalEcpRetentionPolicyTagsUrl

The internal URL of the Exchange Control Panel for retention policy tags.

InternalEcpPublishingUrl

The internal URL of the Exchange Control Panel for publishing.

InternalEwsUrl

The internal URL of Exchange Web Services.

InternalOABUrl

The internal URL of the offline address book (OAB).

InternalUMUrl

The internal URL of the Unified Messaging services.

InternalWebClientUrls

The internal URLs of the Exchange Web client.

MailboxDN

The distinguished name of the mailbox database of the user's mailbox.

PublicFolderServer

The name of the Public Folders server.

ActiveDirectoryServer

The name of the Active Directory server.

ExternalMailboxServer

The name of the RPC over HTTP server.

ExternalMailboxServerRequiresSSL

Indicates whether the RPC over HTTP server requires SSL.

ExternalMailboxServerAuthenticationMethods

The authentication methods that are supported by the RPC over HTTP server.

EcpVoicemailUrlFragment

The URL fragment of the Exchange Control Panel for voice mail Customization.

EcpEmailSubscriptionsUrlFragment

The URL fragment of the Exchange Control Panel for e-mail Subscriptions.

EcpTextMessagingUrlFragment

The URL fragment of the Exchange Control Panel for text messaging.

EcpDeliveryReportUrlFragment

The URL fragment of the Exchange Control Panel for delivery reports.

EcpRetentionPolicyTagsUrlFragment

The URL fragment of the Exchange Control Panel for retention policy tags.

EcpPublishingUrlFragment

The URL fragment of the Exchange Control Panel for publishing.

ExternalEcpUrl

The external URL of the Exchange Control Panel.

ExternalEcpVoicemailUrl

The external URL of the Exchange Control Panel for voice mail customization.

ExternalEcpEmailSubscriptionsUrl

The external URL of the Exchange Control Panel for e-mail subscriptions.

ExternalEcpTextMessagingUrl

The external URL of the Exchange Control Panel for text messaging.

ExternalEcpDeliveryReportUrl

The external URL of the Exchange Control Panel for delivery reports.

ExternalEcpRetentionPolicyTagsUrl

The external URL of the Exchange Control Panel for retention policy tags.

ExternalEcpPublishingUrl

The external URL of the Exchange Control Panel for Publishing.

ExternalEwsUrl

The external URL of Exchange Web Services.

ExternalOABUrl

The external URL of the offline address book (OAB).

ExternalUMUrl

The external URL of the Unified Messaging services.

ExternalWebClientUrls

The external URLs of the Exchange Web client.

CrossOrganizationSharingEnabled

Indicates that cross-organization sharing is enabled.

AlternateMailboxes

The collection of alternate mailboxes.

CasVersion

The version of the Client Access server that is serving the request (for example, 14.XX.YYYY.ZZZ)

EwsSupportedSchemas

A comma-separated list of schema versions supported by Exchange Web Services. The schema version values will be the same as the values of the ExchangeServerVersion enumeration.

InternalPop3Connections

The internal connection settings list for the POP3 protocol.

ExternalPop3Connections

The external connection settings list for the POP3 protocol.

InternalImap4Connections

The internal connection settings list for the IMAP4 protocol.

ExternalImap4Connections

The external connection settings list for the IMAP4 protocol.

InternalSmtpConnections

The internal connection settings list for the SMTP protocol.

ExternalSmtpConnections

The external connection settings list for the SMTP protocol.

ExchangeRpcUrl

The URL of the remote procedure call (RPC) interface to the server.

ExternalEwsVersion

The version of the external Exchange Web Services server.

MobileMailboxPolicy

Mobile Mailbox policy settings.

To get the user settings

  1. Use the GetUserSettings method to generate the request that retrieves configuration information for a user, as shown in the following example. In this example, only some of the possible user settings are requested, and only the requested settings are returned from the server.

    AutodiscoverService autodiscoverService = new AutodiscoverService("domain.contoso.com");
    autodiscoverService.Credentials = new NetworkCredential("User1", "password", "domain.contoso.com");
    
    // Submit a request and get the settings. The response contains only the
    // setttings that are requested, if they exist.
    
    GetUserSettingsResponse userresponse = autodiscoverService.GetUserSettings(
        "User1@Contoso.com",
        UserSettingName.UserDN,
        UserSettingName.UserDeploymentId,
        UserSettingName.InternalMailboxServer,
        UserSettingName.MailboxDN,
        UserSettingName.PublicFolderServer,
        UserSettingName.ActiveDirectoryServer,
        UserSettingName.ExternalMailboxServer,
        UserSettingName.EcpDeliveryReportUrlFragment,
        UserSettingName.EcpPublishingUrlFragment,
        UserSettingName.EcpTextMessagingUrlFragment, 
        UserSettingName.ExternalEwsUrl,
        UserSettingName.CasVersion,
        UserSettingName.EwsSupportedSchemas);
    
  2. Parse the collection to display each element of the returned key value pair. The following example shows how to parse through each returned element and display the name and value of each key value pair.

    // Display each retrieved value. The settings are part of a key value pair.
    foreach (KeyValuePair<UserSettingName, Object> usersetting in userresponse.Settings)
    {
        Console.WriteLine(usersetting.Key.ToString() + ": " + usersetting.Value);
    }
    

    Alternatively, you can obtain the value of a specific element. In the following example, the UserDisplayName setting is to be displayed.

    // Display a specific setting, such as UserDisplayName.
    Console.WriteLine(userresponse.Settings[UserSettingName.UserDisplayName]);
    

Example

The following example shows how to create an AutodiscoverService object and uses the GetUserSetting method to obtain and display a user's configuration settings.

AutodiscoverService autodiscoverService = new AutodiscoverService("domain.contoso.com");
autodiscoverService.Credentials = new WebCredentials("User1", "password", "domain.contoso.com");


// Get the user settings.
// Submit a request and get the settings. The response contains only the
// settings that are requested, if they exist. 
GetUserSettingsResponse userresponse = autodiscoverService.GetUserSettings(
    "User1@Contoso.com",
    UserSettingName.UserDN,
    UserSettingName.UserDeploymentId,
    UserSettingName.InternalMailboxServer,
    UserSettingName.MailboxDN,
    UserSettingName.PublicFolderServer,
    UserSettingName.ActiveDirectoryServer,
    UserSettingName.ExternalMailboxServer,
    UserSettingName.EcpDeliveryReportUrlFragment,
    UserSettingName.EcpPublishingUrlFragment,
    UserSettingName.EcpTextMessagingUrlFragment, 
    UserSettingName.ExternalEwsUrl,
    UserSettingName.CasVersion,
    UserSettingName.EwsSupportedSchemas);

// Display each retrieved value. The settings are part of a key value pair.
foreach (KeyValuePair<UserSettingName, Object> usersetting in userresponse.Settings)
{
    Console.WriteLine(usersetting.Key.ToString() + ": " + usersetting.Value);
}

The following example shows the XML request that is sent by the client to the server when the client submits an Autodiscover request.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:a="https://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="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <a:RequestedServerVersion>Exchange2010</a:RequestedServerVersion>
    <wsa:Action>https://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetUserSettings</wsa:Action>
    <wsa:To>https://autodiscover.exchange.microsoft.com/autodiscover/autodiscover.svc</wsa:To>
  </soap:Header>
  <soap:Body>
    <a:GetUserSettingsRequestMessage xmlns:a="https://schemas.microsoft.com/exchange/2010/Autodiscover">
      <a:Request>
        <a:Users>
          <a:User>
            <a:Mailbox>User1@Contoso.com</a:Mailbox>
          </a:User>
        </a:Users>
        <a:RequestedSettings>
          <a:Setting>UserDisplayName</a:Setting>
          <a:Setting>UserDN</a:Setting>
          <a:Setting>UserDeploymentId</a:Setting>
          <a:Setting>InternalMailboxServer</a:Setting>
          <a:Setting>MailboxDN</a:Setting>
          <a:Setting>PublicFolderServer</a:Setting>
          <a:Setting>ActiveDirectoryServer</a:Setting>
          <a:Setting>ExternalMailboxServer</a:Setting>
          <a:Setting>EcpDeliveryReportUrlFragment</a:Setting>
          <a:Setting>EcpPublishingUrlFragment</a:Setting>
          <a:Setting>EcpTextMessagingUrlFragment</a:Setting>
          <a:Setting>ExternalEwsUrl</a:Setting>
          <a:Setting>CasVersion</a:Setting>
          <a:Setting>EwsSupportedSchemas</a:Setting>
        </a:RequestedSettings>
      </a:Request>
    </a:GetUserSettingsRequestMessage>
  </soap:Body>
</soap:Envelope>

The following example shows the XML response that is returned by the server after it parses the request from the client.

<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing">
  <s:Header>
    <a:Action s:mustUnderstand="1">https://schemas.microsoft.com/exchange/2010/
        Autodiscover/Autodiscover/GetUserSettingsResponse</a:Action>
    <h:ServerVersionInfo xmlns:h="https://schemas.microsoft.com/exchange/2010/Autodiscover" 
        xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
      <h:MajorVersion>14</h:MajorVersion>
      <h:MinorVersion>1</h:MinorVersion>
      <h:MajorBuildNumber>160</h:MajorBuildNumber>
      <h:MinorBuildNumber>4</h:MinorBuildNumber>
      <h:Version>Exchange2010_SP1</h:Version>
    </h:ServerVersionInfo>
  </s:Header>
  <s:Body>
    <GetUserSettingsResponseMessage xmlns="https://schemas.microsoft.com/exchange/2010/Autodiscover">
      <Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <ErrorCode>NoError</ErrorCode>
        <ErrorMessage />
        <UserResponses>
          <UserResponse>
            <ErrorCode>NoError</ErrorCode>
            <ErrorMessage>No error.</ErrorMessage>
            <RedirectTarget i:nil="true" />
            <UserSettingErrors />
            <UserSettings>
              <UserSetting i:type="StringSetting">
                <Name>UserDisplayName</Name>
                <Value>User 1</Value>
              </UserSetting>
              <UserSetting i:type="StringSetting">
                <Name>UserDN</Name>
                <Value>/o=microsoft/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=User1</Value>
              </UserSetting>
              <UserSetting i:type="StringSetting">
                <Name>UserDeploymentId</Name>
                <Value>649d50b8-a1ce-4bac-8ace-2321e463f701</Value>
              </UserSetting>
              <UserSetting i:type="StringSetting">
                <Name>CasVersion</Name>
                <Value>14.01.0160.004</Value>
              </UserSetting>
              <UserSetting i:type="StringSetting">
                <Name>EwsSupportedSchemas</Name>
                <Value>Exchange2007, Exchange2007_SP1, Exchange2010, Exchange2010_SP1, Exchange2010_SP2</Value>
              </UserSetting>
              <UserSetting i:type="StringSetting">
                <Name>InternalMailboxServer</Name>
                <Value>DF-M14-05.Contoso.com</Value>
              </UserSetting>
              <UserSetting i:type="StringSetting">
                <Name>ActiveDirectoryServer</Name>
                <Value>CO1-EXCH-DC-02.Contoso.com</Value>
              </UserSetting>
              <UserSetting i:type="StringSetting">
                <Name>MailboxDN</Name>
                <Value>/o=microsoft/ou=Exchange Administrative Group 
                  (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=server.Contoso.com/cn=Contoso Private MDB</Value>
              </UserSetting>
              <UserSetting i:type="StringSetting">
                <Name>PublicFolderServer</Name>
                <Value>DF-P14-01.Contoso.com</Value>
              </UserSetting>
              <UserSetting i:type="StringSetting">
                <Name>EcpDeliveryReportUrlFragment</Name>
                <Value>PersonalSettings/DeliveryReport.aspx?exsvurl=1&amp;IsOWA=&lt;IsOWA&gt;&amp;MsgID=&lt;MsgID&gt;&amp;Mbx=&lt;Mbx&gt;</Value>
              </UserSetting>
              <UserSetting i:type="StringSetting">
                <Name>EcpTextMessagingUrlFragment</Name>
                <Value>?p=sms/textmessaging.slab&amp;exsvurl=1</Value>
              </UserSetting>
              <UserSetting i:type="StringSetting">
                <Name>EcpPublishingUrlFragment</Name>
                <Value>customize/calendarpublishing.slab?exsvurl=1&amp;FldID=&lt;FldID&gt;</Value>
              </UserSetting>
              <UserSetting i:type="StringSetting">
                <Name>ExternalEwsUrl</Name>
                <Value>https://mail.exchange.microsoft.com/EWS/Exchange.asmx</Value>
              </UserSetting>
              <UserSetting i:type="StringSetting">
                <Name>ExternalMailboxServer</Name>
                <Value>mail.Contoso.com</Value>
              </UserSetting>
            </UserSettings>
          </UserResponse>
        </UserResponses>
      </Response>
    </GetUserSettingsResponseMessage>
  </s:Body>
</s:Envelope

Compiling the code

For information about compiling this code, see Getting started with the EWS Managed API 2.0.

Robust programming

  • Write appropriate error handling code for common search errors.

  • Review the client request XML that is sent to the Exchange server.

  • Review the server response XML that is sent from the Exchange server.

  • Set the service binding as shown in Setting the Exchange service URL by using the EWS Managed API 2.0. Do not hard code URLs because if mailboxes move, they might be serviced by a different Client Access server. If the client cannot connect to the service, retry setting the binding by using the AutodiscoverUrl(String) method.

  • Set the target Exchange Web Services schema version by setting the requestedServerVersion parameter of the ExchangeService constructor. For more information, see Versioning EWS requests by using the EWS Managed API 2.0.

Security

  • Use HTTP with SSL for all communication between client and server.

  • Always validate the server certificate that is used for establishing the SSL connections. For more information, see Validating X509 certificates by using the EWS Managed API 2.0.

  • Do not include user names and passwords in trace files.

  • Verify that Autodiscover lookups that use HTTP GET to find an endpoint always prompt for user confirmation; otherwise, they should be blocked.