none
Authentication getting failed for Office 365 account using Microsoft.Exchange.WebServices RRS feed

  • Question

  • Hi,

    I am using Microsoft.Exchange.WebServices.dll(15.0) to download Office 365 account's mails.

    Sometimes authentication got failed with following exception

    ---------------------------------------------------------------------------------------

    System.ArgumentException: The specified name is not a forest, Active Directory domain controller, ADAM instance, or ADAM configuration set.
    Parameter name: context
       at System.DirectoryServices.ActiveDirectory.ActiveDirectorySite.ValidateArgument(DirectoryContext context, String siteName)
       at System.DirectoryServices.ActiveDirectory.ActiveDirectorySite.FindByName(DirectoryContext context, String siteName)
       at System.DirectoryServices.ActiveDirectory.ActiveDirectorySite.GetComputerSite()
       at Microsoft.Exchange.WebServices.Autodiscover.DirectoryHelper.GetSiteName()
       at Microsoft.Exchange.WebServices.Autodiscover.DirectoryHelper.GetScpUrlList(String domainName, String ldapPath, Int32& maxHops)
       at Microsoft.Exchange.WebServices.Autodiscover.DirectoryHelper.GetAutodiscoverScpUrlsForDomain(String domainName)
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.DefaultGetScpUrlsForDomain(String domainName)
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetAutodiscoverServiceUrls(String domainName, Int32& scpHostCount)
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetAutodiscoverServiceHosts(String domainName, Int32& scpHostCount)
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetSettings[TGetSettingsResponseCollection,TSettingName](List`1 identities, List`1 settings, Nullable`1 requestedVersion, GetSettingsMethod`2 getSettingsMethod, Func`1 getDomainMethod)
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(List`1 smtpAddresses, List`1 settings)
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetSoapUserSettings(String smtpAddress, List`1 requestedSettings)
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)

    -------------------------------------------------------------------------------------------------------------------------------

    and when I retry same account again it authenticate account successfully.I am using Impersonation to authenticate id. 

    The behavior is inconsistent when we authenticate.


    Tuesday, October 7, 2014 4:28 PM

All replies

  • After enabling the trace, here is what i got: - 

    service started
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:22Z">
    Determining which endpoints are enabled for host cloudin.onmicrosoft.com
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:22Z">
    Request error: The remote name could not be resolved: 'cloudin.onmicrosoft.com'
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:22Z">
    No Autodiscover endpoints are available for host cloudin.onmicrosoft.com
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:22Z">
    Determining which endpoints are enabled for host autodiscover.cloudin.onmicrosoft.com
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:29Z">
    Request error: Unable to connect to the remote server
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:29Z">
    No Autodiscover endpoints are available for host autodiscover.cloudin.onmicrosoft.com
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:29Z">
    Trying to get Autodiscover redirection URL from http://autodiscover.cloudin.onmicrosoft.com/autodiscover/autodiscover.xml.
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:29Z">
    Redirection URL found: 'https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml'
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:29Z">
    Determining which endpoints are enabled for host autodiscover-s.outlook.com
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:30Z">
    Request error: The remote server returned an error: (401) Unauthorized.
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:30Z">
    Host returned enabled endpoint flags: Legacy, Soap, WsSecurity, WSSecuritySymmetricKey, WSSecurityX509Cert
    </Trace>
    <Trace Tag="AutodiscoverRequestHttpHeaders" Tid="6" Time="2014-10-07 15:26:30Z">
    POST /autodiscover/autodiscover.svc HTTP/1.1
    Content-Type: text/xml; charset=utf-8
    Accept: text/xml
    User-Agent: ExchangeServicesClient/15.00.0516.014
    
    
    </Trace>
    <Trace Tag="AutodiscoverRequest" Tid="6" Time="2014-10-07 15:26:30Z" Version="15.00.0516.014">
      <?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>Exchange2013</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>admin@cloudin.onmicrosoft.com</a:Mailbox>
                </a:User>
              </a:Users>
              <a:RequestedSettings>
                <a:Setting>InternalEwsUrl</a:Setting>
                <a:Setting>ExternalEwsUrl</a:Setting>
              </a:RequestedSettings>
            </a:Request>
          </a:GetUserSettingsRequestMessage>
        </soap:Body>
      </soap:Envelope>
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:32Z">
    Request to https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc returned redirection to https://pod51055.outlook.com/autodiscover/autodiscover.svc
    </Trace>
    <Trace Tag="AutodiscoverRequestHttpHeaders" Tid="6" Time="2014-10-07 15:26:32Z">
    POST /autodiscover/autodiscover.svc HTTP/1.1
    Content-Type: text/xml; charset=utf-8
    Accept: text/xml
    User-Agent: ExchangeServicesClient/15.00.0516.014
    
    
    </Trace>
    <Trace Tag="AutodiscoverRequest" Tid="6" Time="2014-10-07 15:26:32Z" Version="15.00.0516.014">
      <?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>Exchange2013</a:RequestedServerVersion>
          <wsa:Action>http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetUserSettings</wsa:Action>
          <wsa:To>https://pod51055.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>admin@cloudin.onmicrosoft.com</a:Mailbox>
                </a:User>
              </a:Users>
              <a:RequestedSettings>
                <a:Setting>InternalEwsUrl</a:Setting>
                <a:Setting>ExternalEwsUrl</a:Setting>
              </a:RequestedSettings>
            </a:Request>
          </a:GetUserSettingsRequestMessage>
        </soap:Body>
      </soap:Envelope>
    </Trace>
    <Trace Tag="AutodiscoverResponseHttpHeaders" Tid="6" Time="2014-10-07 15:26:33Z">
    HTTP/1.1 200 OK
    Transfer-Encoding: chunked
    request-id: 374ecfec-959b-43f9-b829-da02d9ce8da7
    X-CalculatedBETarget: sinpr04mb170.apcprd04.prod.outlook.com
    X-DiagInfo: SINPR04MB170
    X-BEServer: SINPR04MB170
    X-FEServer: SINPR04CA006
    Cache-Control: private
    Content-Type: text/xml; charset=utf-8
    Date: Tue, 07 Oct 2014 15:26:31 GMT
    Set-Cookie: X-BackEndCookie=admin@cloudin.onmicrosoft.com=u56Lnp2ejJqBzZ2aysiansrSnsqZmtLLzcua0sfMx8bSx5zIx5ucys7Gys7OgZyTkIqblpHRkJGSlpyNkIyQmYvRnJCSgc3PzsvSzs7Sz8mrzsrFzcnFzM4=; expires=Thu, 06-Nov-2014 15:26:31 GMT; path=/autodiscover; secure; HttpOnly
    Server: Microsoft-IIS/8.0
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    
    
    </Trace>
    <Trace Tag="AutodiscoverResponse" Tid="6" Time="2014-10-07 15:26:33Z" Version="15.00.0516.014">
      <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing">
        <s:Header>
          <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetUserSettingsResponse</a:Action>
          <h:ServerVersionInfo xmlns:h="http://schemas.microsoft.com/exchange/2010/Autodiscover" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <h:MajorVersion>15</h:MajorVersion>
            <h:MinorVersion>0</h:MinorVersion>
            <h:MajorBuildNumber>1044</h:MajorBuildNumber>
            <h:MinorBuildNumber>8</h:MinorBuildNumber>
            <h:Version>Exchange2013_SP1</h:Version>
          </h:ServerVersionInfo>
        </s:Header>
        <s:Body>
          <GetUserSettingsResponseMessage xmlns="http://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>
                    <UserSettingError>
                      <ErrorCode>SettingIsNotAvailable</ErrorCode>
                      <ErrorMessage>User setting 'InternalEwsUrl' is not available. </ErrorMessage>
                      <SettingName>InternalEwsUrl</SettingName>
                    </UserSettingError>
                  </UserSettingErrors>
                  <UserSettings>
                    <UserSetting i:type="StringSetting">
                      <Name>ExternalEwsUrl</Name>
                      <Value>https://outlook.office365.com/EWS/Exchange.asmx</Value>
                    </UserSetting>
                  </UserSettings>
                </UserResponse>
              </UserResponses>
            </Response>
          </GetUserSettingsResponseMessage>
        </s:Body>
      </s:Envelope>
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:33Z">
    Determining which endpoints are enabled for host cloudin.onmicrosoft.com
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:33Z">
    Request error: The remote name could not be resolved: 'cloudin.onmicrosoft.com'
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:33Z">
    No Autodiscover endpoints are available for host cloudin.onmicrosoft.com
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:33Z">
    Determining which endpoints are enabled for host autodiscover.cloudin.onmicrosoft.com
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:38Z">
    Request error: Unable to connect to the remote server
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:38Z">
    No Autodiscover endpoints are available for host autodiscover.cloudin.onmicrosoft.com
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:38Z">
    Trying to get Autodiscover redirection URL from http://autodiscover.cloudin.onmicrosoft.com/autodiscover/autodiscover.xml.
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:39Z">
    Redirection URL found: 'https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml'
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:39Z">
    Determining which endpoints are enabled for host autodiscover-s.outlook.com
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:39Z">
    Request error: The remote server returned an error: (401) Unauthorized.
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:39Z">
    Host returned enabled endpoint flags: Legacy, Soap, WsSecurity, WSSecuritySymmetricKey, WSSecurityX509Cert
    </Trace>
    <Trace Tag="AutodiscoverRequestHttpHeaders" Tid="6" Time="2014-10-07 15:26:39Z">
    POST /autodiscover/autodiscover.svc HTTP/1.1
    Content-Type: text/xml; charset=utf-8
    Accept: text/xml
    User-Agent: ExchangeServicesClient/15.00.0516.014
    
    
    </Trace>
    <Trace Tag="AutodiscoverRequest" Tid="6" Time="2014-10-07 15:26:39Z" Version="15.00.0516.014">
      <?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>Exchange2013</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>admin@cloudin.onmicrosoft.com</a:Mailbox>
                </a:User>
              </a:Users>
              <a:RequestedSettings>
                <a:Setting>InternalEwsUrl</a:Setting>
                <a:Setting>ExternalEwsUrl</a:Setting>
              </a:RequestedSettings>
            </a:Request>
          </a:GetUserSettingsRequestMessage>
        </soap:Body>
      </soap:Envelope>
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="6" Time="2014-10-07 15:26:42Z">
    Request to https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc returned redirection to https://pod51055.outlook.com/autodiscover/autodiscover.svc
    </Trace>
    <Trace Tag="AutodiscoverRequestHttpHeaders" Tid="6" Time="2014-10-07 15:26:42Z">
    POST /autodiscover/autodiscover.svc HTTP/1.1
    Content-Type: text/xml; charset=utf-8
    Accept: text/xml
    User-Agent: ExchangeServicesClient/15.00.0516.014
    
    
    </Trace>
    <Trace Tag="AutodiscoverRequest" Tid="6" Time="2014-10-07 15:26:42Z" Version="15.00.0516.014">
      <?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>Exchange2013</a:RequestedServerVersion>
          <wsa:Action>http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetUserSettings</wsa:Action>
          <wsa:To>https://pod51055.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>admin@cloudin.onmicrosoft.com</a:Mailbox>
                </a:User>
              </a:Users>
              <a:RequestedSettings>
                <a:Setting>InternalEwsUrl</a:Setting>
                <a:Setting>ExternalEwsUrl</a:Setting>
              </a:RequestedSettings>
            </a:Request>
          </a:GetUserSettingsRequestMessage>
        </soap:Body>
      </soap:Envelope>
    </Trace>
    <Trace Tag="AutodiscoverResponseHttpHeaders" Tid="6" Time="2014-10-07 15:26:42Z">
    HTTP/1.1 200 OK
    Transfer-Encoding: chunked
    request-id: d4251f8b-fba5-467e-b884-1a3f2a3d82f9
    X-CalculatedBETarget: sinpr04mb170.apcprd04.prod.outlook.com
    X-DiagInfo: SINPR04MB170
    X-BEServer: SINPR04MB170
    X-FEServer: SINPR04CA006
    Cache-Control: private
    Content-Type: text/xml; charset=utf-8
    Date: Tue, 07 Oct 2014 15:26:40 GMT
    Set-Cookie: X-BackEndCookie=admin@cloudin.onmicrosoft.com=u56Lnp2ejJqBzZ2aysiansrSnsqZmtLLzcua0sfMx8bSx5zIx5ucys7Gys7OgZyTkIqblpHRkJGSlpyNkIyQmYvRnJCSgc3PzsvSzs7Sz8mrzsrFzcnFy88=; expires=Thu, 06-Nov-2014 15:26:40 GMT; path=/autodiscover; secure; HttpOnly
    Server: Microsoft-IIS/8.0
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    
    
    </Trace>
    <Trace Tag="AutodiscoverResponse" Tid="6" Time="2014-10-07 15:26:42Z" Version="15.00.0516.014">
      <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing">
        <s:Header>
          <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetUserSettingsResponse</a:Action>
          <h:ServerVersionInfo xmlns:h="http://schemas.microsoft.com/exchange/2010/Autodiscover" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <h:MajorVersion>15</h:MajorVersion>
            <h:MinorVersion>0</h:MinorVersion>
            <h:MajorBuildNumber>1044</h:MajorBuildNumber>
            <h:MinorBuildNumber>8</h:MinorBuildNumber>
            <h:Version>Exchange2013_SP1</h:Version>
          </h:ServerVersionInfo>
        </s:Header>
        <s:Body>
          <GetUserSettingsResponseMessage xmlns="http://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>
                    <UserSettingError>
                      <ErrorCode>SettingIsNotAvailable</ErrorCode>
                      <ErrorMessage>User setting 'InternalEwsUrl' is not available. </ErrorMessage>
                      <SettingName>InternalEwsUrl</SettingName>
                    </UserSettingError>
                  </UserSettingErrors>
                  <UserSettings>
                    <UserSetting i:type="StringSetting">
                      <Name>ExternalEwsUrl</Name>
                      <Value>https://outlook.office365.com/EWS/Exchange.asmx</Value>
                    </UserSetting>
                  </UserSettings>
                </UserResponse>
              </UserResponses>
            </Response>
          </GetUserSettingsResponseMessage>
        </s:Body>
      </s:Envelope>
    </Trace>
    <Trace Tag="EwsRequestHttpHeaders" Tid="6" Time="2014-10-07 15:26:42Z">
    POST /EWS/Exchange.asmx HTTP/1.1
    Content-Type: text/xml; charset=utf-8
    Accept: text/xml
    User-Agent: ExchangeServicesClient/15.00.0516.014
    Accept-Encoding: gzip,deflate
    
    
    </Trace>
    

    Any ideas why this could be happening?

    Tuesday, October 7, 2014 4:29 PM
  • The stacktrace points to the error occurring during the SCP lookup where its trying to scan the Local Active Directory for an SCP endpoint which it will try by default before using DNS. Generally if your using Office365 you don't want to do this so with the Managed API you can disable the SCP lookup which will also make the code more responsive eg

                service.Credentials = ncCred;
                service.EnableScpLookup = false;
                service.AutodiscoverUrl("user@domain.com", AutoDiscoCallBack);
    Cheers
    Glen

    Wednesday, October 8, 2014 4:26 AM
  • Hi Glen,

    Thanks for the reply.

    I already set 

    service.EnableScpLookup=false;

    Even though it is looking for Scp endpoint in the Local Active Directory.

    Wednesday, October 8, 2014 5:13 AM
  • You might want to post the full code your using.

    In theory you don't need to use AutoDiscover with Office365 because you will always get the load balanced Endpoint https://outlook.office365.com/EWS/Exchange.asmx .

    You can also try just use the Autodiscover class as well eg

                        AutodiscoverService adAutoDiscoverService = new AutodiscoverService(ExchangeVersion.Exchange2010_SP1);
                        adAutoDiscoverService.Url = new Uri(" https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc");
                        adAutoDiscoverService.Credentials = new NetworkCredential(UserName, Password);
                        adAutoDiscoverService.EnableScpLookup = false;
                        adAutoDiscoverService.RedirectionUrlValidationCallback = adAutoDiscoCallBack;
                        adAutoDiscoverService.PreAuthenticate = true;
                        adAutoDiscoverService.KeepAlive = false;
                        GetUserSettingsResponse adResponse = adAutoDiscoverService.GetUserSettings(emEmailAddress, (new UserSettingName[1] { UserSettingName.ExternalEwsUrl }));
    Cheers
    Glen

    Wednesday, October 8, 2014 5:32 AM
  • hi,

    Following is the code I use to authenticate the user

    ExchangeService f_objExchangeService    = new ExchangeService(ExchangeVersion.Exchange2010_SP1); 
    f_objExchangeService.TraceEnabled      	= true;
    f_objExchangeService.EnableScpLookup    = false;
    f_objExchangeService.Credentials        = new  WebCredentials(p_office365UserId, p_office365UserPassword);
    
    f_objExchangeService.AutodiscoverUrl(p_office365UserId, RedirectionUrlValidationCallback); 
    
    if ((f_objExchangeService != null) && (f_objExchangeService.Url != null))
     {
       HttpWebRequest f_httpWebRequest = (HttpWebRequest)WebRequest.Create(f_objExchangeService.Url);
           if (f_httpWebRequest != null)
              {
                f_httpWebRequest.KeepAlive          = false;
                f_httpWebRequest.SendChunked        = true;
                f_httpWebRequest.ReadWriteTimeout   = int.MaxValue;
                f_httpWebRequest.Timeout            = int.MaxValue;
                f_objExchangeService.Timeout        = int.MaxValue;
               }
     }
    ---------------------------------------------------------
    
      private bool RedirectionUrlValidationCallback(String redirectionUrl)
            {
                // Perform validation.
                // Validation is developer dependent to ensure a safe redirect.
                return (redirectionUrl == @"https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml");
                //return true;
            }
    Wednesday, October 8, 2014 9:59 AM
  • I would make sure your using the latest version 2.2 of the Managed API, the trace you posted was from a when Autodiscover worked what does a trace look like when it doesn't work.  Can you reproduce the issue using the EWSEditor http://ewseditor.codeplex.com/

    Cheers
    Glen

    Thursday, October 9, 2014 5:29 AM
  • Hi,

         Th trace contains logs for both the scenarios, the one in which it fails (the initial lines in the logs)and the one which works. Initial part of trace shows that the authentication got fail.

    If possible I will give you new trace reproducing issue.

    I tried some experiments.

    I add CName for Autodiscover in Domain Controller DNS.

    and run the command 

     ipconfig/registerdns

    on machine. 

    It is working for me now.But I am not sure this is the exact solution. Any suggestions as to why it was failing?


    Thursday, October 9, 2014 6:22 AM