Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

ServiceRequestException Message : Request failed. The remote server returned an error: (401) Unauthorized

$
0
0

I am trying to read from an inbox mail folder using the Exchange Web Services Managed API and receive the above error message. I'm basically using C# code from the "Getting Started with the EWS Managed API 1.0" document.  Has anyone seen this before?

Thanks.

The exception is as folows:

 Name    : ServiceRequestException Message : Request failed. The remote server returned an error: (401) Unauthorized. Trace   :    at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.InternalExecute()
   at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
   at Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems[TItem](IEnumerable`1 parentFolderIds, SearchFilter searchFilter, String queryString, ViewBase view, Grouping groupBy, ServiceErrorHandling errorHandlingMode)
   at Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems(FolderId parentFolderId, SearchFilter searchFilter, ItemView view)
   at ewstest4.EwsAccess.GetMessages(DateTime& lastTime)

*** Inner Exception ***
 Name    : WebException Message : The remote server returned an error: (401) Unauthorized. Trace   :    at System.Net.HttpWebRequest.GetResponse()
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.Emit()
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.InternalExecute()

The code (somewhat edited) is the following: (The exception takes place on the FindItems call)

_ExchService = new ExchangeService (ExchangeVersion.Exchange2007_SP1);
ServicePointManager.ServerCertificateValidationCallback = EwsAccess.CertificateValidationCallBack;
_ExchService.AutodiscoverUrl (accountName);
_ExchService.Credentials = new NetworkCredential (accountlName, password, domain);
FindItemsResults<Item> findResults = _ExchService.FindItems (WellKnownFolderName.Inbox, new ItemView (5));

 



Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>