Autodiscover Service programmatically RRS feed

  • Question

  • Hi,

    I am software developer. I am trying to make an autodiscover client programmatically in C#.

    I used the code below:


    string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><xs:schema"

                + "xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\""

                + "xmlns:mstns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""

                + "targetNamespace=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\""

                + "elementFormDefault=\"unqualified\" id=\"requestschema2006\">"

                + "<xs:element name=\"Autodiscover\">"

                + "<xs:complexType>"

                + "<xs:sequence>"

                + "<xs:element name=\"Request\" type=\"RequestType\"/>"

                + "</xs:sequence>"

                + "</xs:complexType>"

                + "</xs:element>"

                + "<xs:complexType name=\"RequestType\">"

                + "<xs:sequence>"

                + "<xs:sequence>"

                + "<xs:element name=\"xxxxxx@microsoft.com\" type=\"xs:string\"/>"

                + "<xs:element name=\"AcceptableResponseSchema\" type=\"xs:string\"/>"

                + "</xs:sequence>"

                + "</xs:sequence>"

                + "</xs:complexType>"

                + "</xs:schema>";

                string url = "https://autodiscover.microsoft.com/autodiscover/autodiscover.xml";

                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

                req.Credentials = new NetworkCredential("xxxxxx@microsoft.com", "xxxxxxx");

                byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(xml);

                req.Method = "POST";

                req.ContentType = "text/xml";

                req.ContentLength = requestBytes.Length;

                Stream requestStream = req.GetRequestStream();

                requestStream.Write(requestBytes, 0, requestBytes.Length);







                    HttpWebResponse res = (HttpWebResponse)req.GetResponse();

                    StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);

                    string backstr = sr.ReadToEnd();





                catch (Exception ex)

                { }


    but the response returned is invalid request error code 600. so what should i do ??


    Monday, August 8, 2011 11:06 PM

All replies

  • Hi,

    the EWS Managed API (http://www.microsoft.com/download/en/details.aspx?id=13480) already implements the AutoDiscover process.

    If you want to do it on your own, you might learn something on how it does it. You can enable tracing on the ExchangeService instance which will dump the AutoDiscover requests to the console. This might help to troubleshoot your problem.

    Kind regards,

    Tuesday, August 9, 2011 8:48 PM
  • Hello O.Tayel,

     Like WebDAV we don't need to deal with xml request - response manually if we are trying to connect with Exchange 2007/2010. Because both server supports Exchange web service API. So, To make client application that finds settings automatically, you can try using below steps:

    1. download and setup EWS Managed API (http://www.microsoft.com/download/en/details.aspx?id=13480) .

    2. add reference to your project.

    3. Add namespace to your page/form

    4. use following code

    public ExchangeService GetSettings(string MailboxAddress, string password)
      ExchangeService service = new ExchangeService();
      service.Credentials = new WebCredentials(MailboxAddress, password);
      service.TraceEnabled = true;
      service.AutodiscoverUrl(MailboxAddress, RedirectionUrlValidationCallback);
      return service;
      catch (Exception)
      return null;
    static bool RedirectionUrlValidationCallback(String redirectionUrl)
      // Perform validation.
      // Validation is developer dependent to ensure a safe edirect.
      return true;



    Tejas Suthar Software Engineer

    • Proposed as answer by Tejas K Suthar Wednesday, August 10, 2011 9:24 AM
    Wednesday, August 10, 2011 9:21 AM
  • I am trying to develop an application on Windows phone 7 . The EWS api dlls aren't supported on windows phone.
    Omar Tayel Ahmed Intern in Cairo Microsoft Innovation Center Senior-2 Student in Cairo University Computer Engineering
    Friday, August 12, 2011 1:08 PM