【发布时间】:2013-01-19 18:39:25
【问题描述】:
我们以编程方式(使用 Microsoft Exchange Web Services Managed API 2.0)访问用户的日历(在 Exchange 2010 SP1 上)。
我们已经能够在我们的开发环境中通过自动发现成功地与 EWS 通信,我们无需在 Exchange 上进行任何特定设置(我们使用默认的开箱即用设置)。
不幸的是,同样的方法不适用于客户端的环境。客户端没有测试环境。我们应该与他们的实时 Exchange 服务器通信。
最初自动发现在客户端环境中不起作用。我们收到以下错误:
Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: The Autodiscover service couldn't be located.
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String emailAddress, List`1 redirectionEmailAddresses, Int32& currentHop)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetLegacyUserSettings[TSettings](String emailAddress)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress, List`1 requestedSettings)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames)
at Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
at Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
所以现在我们明确指定 EWS 的 URL。这给了我们以下错误:
Microsoft.Exchange.WebServices.Data.ServiceRequestException: The request failed. The remote server returned an error: (401) Unauthorized. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(HttpWebRequest request)
--- End of inner exception stack trace ---
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(HttpWebRequest request)
at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute()
at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
at Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder(FolderId folderId, PropertySet propertySet)
at Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder[TFolder](FolderId folderId, PropertySet propertySet)
at Microsoft.Exchange.WebServices.Data.CalendarFolder.Bind(ExchangeService service, FolderId id)
以下代码第5行抛出异常:
ServicePointManager.ServerCertificateValidationCallback = this.CertificateValidationCallBack;
ExchangeService exchangeWebService = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
exchangeWebService.Credentials = new WebCredentials("username@domain.local", "myPassword");
exchangeWebService.AutodiscoverUrl("username@domain.local", this.RedirectionUrlValidationCallback);
**CalendarFolder calendarFolder = CalendarFolder.Bind(exchangeWebService, new FolderId(WellKnownFolderName.Calendar, userName));**
CalendarView calendarView = new CalendarView(startDate, endDate);
calendarView.PropertySet = new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.IsRecurring, AppointmentSchema.AppointmentType, AppointmentSchema.End, AppointmentSchema.Duration);
FindItemsResults<Appointment> findResults = calendarFolder.FindAppointments(calendarView);
我们不介意自动发现不起作用,因为我们可以明确指定 EWS 的 URL。我们想知道的是,我们需要在客户端的 Exchange 实例上检查哪些设置、权限等,以确定引发上述异常 (ServiceRequestException) 的原因。
我们已请求在客户端 Exchange 实例上的 Exchange 命令行管理程序上执行以下命令:
Test-OutlookWebServices –Identity username
Get-OrganizationConfig
我们尚未收到结果。如果还有其他需要检查的地方,请告诉我们。
【问题讨论】:
-
我没有使用托管 API 的经验(我执行原始 SOAP 调用),但我没有看到您尝试连接的 URL。在我的情况下,它必须是 .asmx 而不是 .wdsl。也许这也适用于你?
-
@jan-doggen 是的。它是asmx。 https:\\...\EWS\Exchange.asmx
标签: c# exchangewebservices exchange-server-2010 ews-managed-api