无法从Exchange Server

时间:2017-01-26 14:20:27

标签: c# exchange-server

我尝试使用交换API从交换服务器获取日历信息,并且我一直遇到以下错误:" Exchange Server不支持所请求的版本"当我初始化日历时。我连接的服务器显然正在运行混合版本的交换。

我的代码如下:

        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);
    }

非常感谢任何帮助。感谢。

1 个答案:

答案 0 :(得分:0)

您需要设置您访问的版本https://msdn.microsoft.com/en-us/library/office/dn741586(v=exchg.150).aspx的ExchangeService对象的版本。如果你只是想让它开始工作我会建议

new ExchangeService(ExchangeVersion.Exchange2007_SP1);

然后,您可以使用

查看服务器正在运行的版本

service.ServerInfo.VersionString属性

您还可以在创建对象之前使用自动发现来确定版本。例如

        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 }))