简体   繁体   中英

Unable to access calendar information from exchange server

I'm trying to get calendar information from an exchange server using the exchange api, and I keep running into the following error: " Exchange Server doesn't support the requested version" when I initialise the calendar. The server I'm connecting to is apparently running a hybrid version of exchange.

My code is as follows:

        ExchangeService service = new ExchangeService();
        service.Credentials = new WebCredentials("user", "pass");

        service.AutodiscoverUrl("url");

        DateTime startDate = DateTime.UtcNow;
        DateTime endDate = startDate.Date.AddHours(23).AddMinutes(59).AddSeconds(59);
        const int NUM_APPTS = 50;

        //error happens on this line
        CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet()); 
        CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);
        cView.PropertySet = new PropertySet(AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Location);
    }

Any help would be much appreciated. Thanks.

You need to set the version of the ExchangeService object that version you accessing https://msdn.microsoft.com/en-us/library/office/dn741586(v=exchg.150).aspx . If you just want to get it working to start i would suggest

new ExchangeService(ExchangeVersion.Exchange2007_SP1);

You can then look at version that the server is running using the

service.ServerInfo.VersionString property

You can also use Autodiscover to determine the version before create the object. eg

        AutodiscoverService adAutoDiscoverService = new AutodiscoverService();
        adAutoDiscoverService.Credentials = ncCred;
        adAutoDiscoverService.EnableScpLookup = true;
        adAutoDiscoverService.RedirectionUrlValidationCallback = adAutoDiscoCallBack;
        adAutoDiscoverService.PreAuthenticate = true;
        adAutoDiscoverService.TraceEnabled = true;
        adAutoDiscoverService.KeepAlive = false;
        GetUserSettingsResponse adResponse = adAutoDiscoverService.GetUserSettings("user@domain.com", (new UserSettingName[1] { UserSettingName.EwsSupportedSchemas }))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM