Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.
Sep 18, 2008
9
US
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));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top