我們以編程方式(使用Microsoft Exchange Web服務託管API 2.0)訪問用戶的日曆(在Exchange 2010 SP1上)。我們需要檢查Exchange上的哪些設置以避免引發ServiceRequestException?
我們已經能夠在我們的開發環境中通過自動發現與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)
所以,現在我們明確指定的URL EWS。這給了我們以下錯誤:
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("[email protected]", "myPassword");
exchangeWebService.AutodiscoverUrl("[email protected]", 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)。
Test-OutlookWebServices –Identity username
Get-OrganizationConfig
我們還沒有收到結果:
我們已要求下面的命令在Exchange管理外殼的Exchange的客戶端的情況下執行。請讓我們知道,如果有什麼我們應該檢查。
我與託管API(我做原料SOAP調用)沒有任何經驗,但我沒有看到你正在試圖連接的URL至。在我的情況下,它必須是.asmx而不是.wdsl。也許這也適用於你? –
@ jan-doggen是的。它是asmx。 https:\\ ... \ EWS \ Exchange.asmx –