Exchange Web Services Autodiscover fails after first login failure RRS feed

  • Question

  • Hi,

    I am writing a C#.NET to send emails using Exchange Web Services APIs. I could find that the code works perfectly when I give the correct user name and password. But, if I give a wrong password on first attempt, the Autodiscover seldom Succeeds.

    Here is my sample code:

    	m_EWService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
    	m_networkCredential = new NetworkCredential();
    	GetCredentials(sMailbox, out m_networkCredential);
    	m_EWService.Credentials = m_networkCredential;
    	m_EWService.AutodiscoverUrl(m_networkCredential.UserName, RedirectionCallback);
    catch (Exception ex)
    	ShowMessage(ex.HResult, ex.Message);

    public static void GetCredentials(string serverName, out NetworkCredential networkCredential) { CREDUI_INFO credui = new CREDUI_INFO(); credui.pszCaptionText = "Please enter the credentails for " + serverName; credui.pszMessageText = ""; credui.cbSize = Marshal.SizeOf(credui); uint authPackage = 0; IntPtr outCredBuffer = new IntPtr(); uint outCredSize; bool save = true; int result = CredUIPromptForWindowsCredentials(ref credui, 0, ref authPackage, IntPtr.Zero, 0, out outCredBuffer, out outCredSize, ref save, 0x1 /* Generic */); var usernameBuf = new StringBuilder(100); var passwordBuf = new StringBuilder(100); var domainBuf = new StringBuilder(100); int maxUserName = 100; int maxDomain = 100; int maxPassword = 100; if (result == 0) { if (CredUnPackAuthenticationBuffer(0, outCredBuffer, outCredSize, usernameBuf, ref maxUserName, domainBuf, ref maxDomain, passwordBuf, ref maxPassword)) { //clear the memory allocated by CredUIPromptForWindowsCredentials CoTaskMemFree(outCredBuffer); networkCredential = new NetworkCredential() { UserName = usernameBuf.ToString(), Password = passwordBuf.ToString(), Domain = domainBuf.ToString() }; return; } } networkCredential = null; }

    Can someone throw some light into how to make it working after the login failure;

    • Moved by Kristin Xie Friday, March 13, 2015 5:58 AM move to appropriate forum
    Thursday, March 12, 2015 3:01 PM

All replies

  • Hi Santhosh,

    Thanks for posting in MSDN forum.

    Based on your description, your case related to EWS(Exchange Web Services) APIs.

    so I would move it to Exchange Development forum to see whether there is an solution.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 13, 2015 5:58 AM
  • Have you tried correcting the credentials and trying again? There's nothing special with EWS you have to do.
    Friday, March 13, 2015 10:31 PM