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

EWS code return Error : Request failed. The remote server returned an error: (403) Forbidden OR (401) Unauthorized

$
0
0

Hi,

To, MSFT.

I am quite unhappy with the limited documentation on EWS.  There should be many useful examples showing the power of EWS and not
just how to call a function.  Also when technology is new , there should be many Videos/Writeup on troubleshooting with EWS with Steps and snapshots.

 

Now I am getting the following Error message and i could not find any resource which can direct me to a solution. 

Microsoft.Exchange.WebServices.Data.ServiceRequestException was unhandled
  Message="Request failed. The remote server returned an error: (403) Forbidden."
  Source="Microsoft.Exchange.WebServices"
  StackTrace:
       at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.InternalExecute()
       at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
       at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalFindFolders(IEnumerable`1 parentFolderIds, SearchFilter searchFilter, FolderView view, ServiceErrorHandling errorHandlingMode)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.FindFolders(FolderId parentFolderId, FolderView view)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.FindFolders(WellKnownFolderName parentFolderName, FolderView view)
       at EWSTest1.Form1.button1_Click(Object sender, EventArgs e) in c:\temp\EWS\EWSTest1\EWSTest1\Form1.cs:line 41
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at EWSTest1.Program.Main() in c:\temp\EWS\EWSTest1\EWSTest1\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Net.WebException
       Message="The remote server returned an error: (403) Forbidden."
       Source="System"
       StackTrace:
            at System.Net.HttpWebRequest.GetResponse()
            at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.Emit()
            at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.InternalExecute()
       InnerException:

 

Following is my code.

 ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

   service.TraceEnabled = true;

   service.Credentials = new WebCredentials("xx@xx.com", "xxxx123");

   service.Url = new Uri("https://mail.xxxxxx.com/EWS/Exchange.asmx");

   FolderView v = new FolderView(5);



   ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback;



   service.FindFolders(WellKnownFolderName.Inbox, v);

   //Error on above line.

 I tried changing the code line as below and I get another Error ....

service.Credentials = new NetworkCredential("xx@xx.com", "xx","xxxxxxxx");
"The remote server returned an error: (401) Unauthorized."

 

How do i resolve.   and what is difference between NetworkCredential and WebCredentials ?


Viewing all articles
Browse latest Browse all 7132

Trending Articles