locked
Connecting Exchange RRS feed

  • Question

  • User987232174 posted

    Hi,

    I have working for several days trying connecting to exchange server but always get the same msg:

    The remote server returned an error: (440) Login Timeout.

    I looked for many examples and routines in google but a haven't found the response and always get the same conclusion. 

    I don´t have any chance to configured  the exchange server since i have read that the problem is the authentication, Form Based Autentication.

    Is there any way to get the connection. Pls, i had spent many days iam desesperate!!!!

    My code is:

     

    private static string server = "https://webmail.company.com";

    private static string path = "/exchange/luis.lopez/Inbox";

    private static string username = "myuser";

    private static string password = "mypwd";

    private CookieContainer authCookies = null;

     

     

    public void Authenticate(){

    string authURI = server + "/exchweb/bin/auth/owaauth.dll";

    // Create the web request body:

    string body = string.Format("destination={0}&username={1}&password={2}", server + path, username, password);

    byte[] bytes = Encoding.UTF8.GetBytes(body);

    // Create the web request:

    HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(authURI);

    request.Method = "POST";

    request.ContentType = "application/x-www-form-urlencoded";request.CookieContainer = new CookieContainer();

    request.ContentLength = bytes.Length;

    // Create the web request content stream:

    using (Stream stream = request.GetRequestStream())

    {

    stream.Write(bytes, 0, bytes.Length);

    stream.Close();

    }

    // Get the response & store the authentication cookies:

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    if (response.Cookies.Count < 2)

    throw new AuthenticationException("Login failed. Is the login / password correct?");

    CookieContainer cookies = new CookieContainer();

    foreach (Cookie myCookie in response.Cookies)

    {

    cookies.Add(myCookie);

    }

     

    response.Close();

    }

     

    ///

    /// Find today's appointments in the public folder calendar and print the results.

    ///

    public void RunQuery()

    {

    string uri = server + path;

    HttpWebRequest request;

    WebResponse response;

    byte[] bytes;

    string start = DateTime.Today.ToString("yyyy/MM/dd");

    string end = DateTime.Today.ToString("yyyy/MM/dd");

    // Note that deep traversals don't work on public folders. In other words, if you

    // need to dig deeper you'll need to split your query into multiple requests.

    string format =@"

    SELECT

    ""urn:schemas:calendar:dtstart"", ""urn:schemas:calendar:dtend"",

    ""urn:schemas:httpmail:subject"", ""urn:schemas:calendar:organizer"",

    ""DAV:parentname""

    FROM

    Scope('SHALLOW TRAVERSAL OF ""{0}""')

    WHERE

    NOT ""urn:schemas:calendar:instancetype"" = 1

    AND ""DAV:contentclass"" = 'urn:content-classes:appointment'

    AND ""urn:schemas:calendar:dtstart"" > '{1}'

    AND ""urn:schemas:calendar:dtend"" < '{2}'

    "
    ;

    bytes = Encoding.UTF8.GetBytes(String.Format(format, uri, start, end));

    // Use the authorization cookies we stored in the authentication method.

    request = (HttpWebRequest)HttpWebRequest.Create(uri);

    request.CookieContainer = authCookies;

    request.Method =
    "SEARCH";

    request.ContentLength = bytes.Length;

    request.ContentType =
    "text/xml";using (Stream requestStream = request.GetRequestStream())

    {

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

    requestStream.Close();

    }

    response = (
    HttpWebResponse)request.GetResponse();using (Stream responseStream = response.GetResponseStream())

    {

    // Parse the XML response to find the data we need.

    XmlDocument document = new XmlDocument();

    document.Load(responseStream);

    XmlNodeList subjectNodes = document.GetElementsByTagName("e:subject");

    XmlNodeList locationNodes = document.GetElementsByTagName("a:parentname");

    XmlNodeList startTimeNodes = document.GetElementsByTagName("d:dtstart");

    XmlNodeList endTimeNodes = document.GetElementsByTagName("d:dtend");

    XmlNodeList organizerNodes = document.GetElementsByTagName("d:organizer");for (int index = 0; index < subjectNodes.Count; index++)

    {

    string subject = subjectNodes[index].InnerText;

    string organizer = organizerNodes[index].InnerText;

    //string location = ParentName(locationNodes[index].InnerText);

    DateTime startTime = DateTime.Parse(startTimeNodes[index].InnerText);

    DateTime endTime = DateTime.Parse(endTimeNodes[index].InnerText);

    // Use a regex to get just the user's first and last names. Note that

    // some appointments may not have a valid user name.

    string pattern = @"""(?.*?)""";

    Regex regex = new Regex(pattern, RegexOptions.None);

    Match matchedText = regex.Match(organizer);

    if (matchedText.Success && matchedText.Groups["name"] != null)

    organizer = matchedText.Groups["name"].Value;

    // Print the results to the console.

    Console.WriteLine("{0} - {1}: {2}", startTime.ToShortTimeString(), endTime.ToShortTimeString(), subject);

    //Console.WriteLine("{0} ({1})", location, organizer);

    Console.WriteLine();

    }

    }

    response.Close();

    }

     

    Many thanks for your Help.

     

     

    Tuesday, April 14, 2009 4:30 PM

All replies

  • User-1955541932 posted

    Did you resolve this issue? I'm using the exact same code with the same 440 error.

    John O. posted a comment with the revision of the code that's supposed to fix it but it didn't help me: http://blog.mbcharbonneau.com/2006/10/26/using-net-and-webdav-to-access-an-exchange-server/ 

    Thanks.

    Monday, June 15, 2009 8:49 PM
  • User-702212968 posted

    Hello Friend,

    Have you fixed this problem ,i am also having the same problem and could not able to find the solution.

    Please let me know have you fixed this issue and how do you fix this as this will be very much helpful for me.

    Thanks in Advance.


    Thursday, July 22, 2010 4:59 AM
  • User-1688960458 posted

    I have found an example:

    Forms Based Authentication

    - Simon

    Saturday, December 11, 2010 2:55 AM