我在Microsoft Exchange Server服务中遇到了以下错误,但仅在移动设备上,因为相同的代码适用于台式机和网络。
错误消息:
System.Net.WebException:远程服务器返回错误:(401) 未经授权。
在System.Net.HttpWebRequest.GetResponse()在 Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse() 在 \ REDMOND \ EXCHANGE \ BUILD \ E15 \ 15.00.0913.015 \ SOURCES \ sources \ dev \ EwsManagedApi \ src \ EwsManagedApi \ Core \ EwsHttpWebRequest.cs:line
为113Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest 请求) \ REDMOND \ EXCHANGE \ BUILD \ E15 \ 15.00.0913.015 \ SOURCES \ sources \ dev \ EwsManagedApi \ src \ EwsManagedApi \ Core \ Requests \ ServiceRequestBase.cs: 行821请求失败。
远程服务器返回错误:(401)未经授权。
代码片段:
// Create an ExchangeService object, set the credentials and the EWS URL.
ExchangeService exchangeService = new ExchangeService();
exchangeService.Credentials = new OAuthCredentials(attachmentToken);
exchangeService.Url = new Uri(ewsUrl);
exchangeService.UseDefaultCredentials = true;
exchangeService.PreAuthenticate = true;
try
{
var getAttachmentsResponse =exchangeService.GetAttachments(attachmentIds.ToArray(),null,new PropertySet(BasePropertySet.FirstClassProperties,ItemSchema.MimeContent));
}
catch (Exception ex)
{
var errMsg = ex.Message;
var errInnerException = ex.InnerException;
message += "Inner Exception :" + errInnerException;
}