views:

33

answers:

1

I am trying to connect to our exchange 2007 server. I have placed lots of exception handling to catch any errors and put them in the application log. Firstly, I have a function which ensures that a user can access the exchange service with the provided credentials:


public bool Logon()
{
    string pwd = /*Get password*/;

    try
    {
        service.Credentials = new WebCredentials(
            username + "@our.domain", pwd);

        service.FindItems(WellKnownFolderName.Outbox, new ItemView(1));
    }
    catch (Exception)
    {
        return false;
    }
    return true;
}

If this function returns false, an entry is placed in the application log reporting that the user failed to login, the process then terminates.

If the function succeeds, then somewhere down the track we call this function; it gets all appointments for the user which are starting in the next 10 minutes:


protected List GetFutureAppointments()
{
    try
    {
        SearchFilter.IsGreaterThanOrEqualTo startTime =
            new SearchFilter.IsGreaterThanOrEqualTo(
                AppointmentSchema.Start, DateTime.Now);

        SearchFilter.IsLessThanOrEqualTo endTime =
                new SearchFilter.IsLessThanOrEqualTo(
                    AppointmentSchema.Start, DateTime.Now.AddMinutes(10));

        SearchFilter filter = 
            new SearchFilter.SearchFilterCollection(LogicalOperator.And,
                new SearchFilter[] { startTime, endTime });

        FindItemsResults results =  
            service.FindItems(
                WellKnownFolderName.Calendar, filter, new ItemView(10));

        return new List(results.Items);
    }
    catch (Exception e)
    {
        Utilities.LogException(e);
        return null;
    }
}

As you can see, the function will catch all exceptions and log them. Showing up in the log is Request failed. The remote server returned an error: (401) Unauthorized. The stack trace points to the service.FindItems() function.

So I'm a little confused and probably don't know enough about exchange or web services or whatever. The logon function is returning true, but then authorization fails later on. Any suggestions?

+1  A: 

It is possible that your credentials give you access to the Outbox but not the the Calendar?

Xavier Poinas
Hmmm, possible. I will ask our tech team and get back to you.
Duracell