Do we need to provide the credentials while using EWS Managed API.

hi All,

 

1> i am trying to use the EWS Managed Api in Exchange server OWA customization.

i have a custom form in owa on which i am fetching all contacts.

while using ExchangeService class when i pass the credentials the code works but when i write

service.UseDefaultCredentials = true; and try to run the code in owa i get follwing exception

When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids.

here is the code that i am using to instantiate the class.

 ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
 service.UseDefaultCredentials = true;
 service.Url = new Uri("https://MYSERVER/EWS/Exchange.asmx");

please let me know where i am going wrong.

 

2> also Another question when i use EWS then i can use UseDefaultCredentials = true; with perfection.

 

also what should i use(EWS API or Normal EWS) to get all contact,calendaritems etc on owa.

Pls Note : i am adding custom page to OWA.

<form id="form1" action="Test.aspx" method="post"> <input id="__VIEWSTATE" name="__VIEWSTATE" type="hidden" value="/wEPDwUJNzgzNDMwNTMzZGQ=" /> </form>
January 10th, 2011 10:21am

It depends how you deployed your form if its deployed in OWA application pool then you have access to the user credentials via the current IIS user context see http://msdn.microsoft.com/en-us/library/bb891801(v=exchg.80).aspx. Just using the default credentials will try to use the credentials of the application pool which wont have rights to the mailbox you can use the work arounds like  (make sure you read the comments) http://blogs.msdn.com/b/rickhall/archive/2009/09/28/exchange-server-2007-sp1-outlook-web-access-customization-part-3-newhelpticket-aspx.aspx .

If you don't want do this you can use Impersonation directly in your code as per http://support.microsoft.com/kb/306158 which is the method I've used successfully in the past.

Cheers
Glen

 

  • Marked as answer by Sandip T Wednesday, January 12, 2011 8:32 AM
Free Windows Admin Tool Kit Click here and download it now
January 11th, 2011 9:03am

hi Glen,

 

yeah it solved the problem.

i used the following way

 

System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext =
((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();

//Insert your code that runs under the security context of the authenticating user here.

impersonationContext.Undo();

 

Thanks again.

Sandeep

January 12th, 2011 11:32am

Hi Glen,

Thanks for your answer. I am trying to read the link you have posted (http://blogs.msdn.com/b/rickhall/archive/2009/09/28/exchange-server-2007-sp1-outlook-web-access-customization-part-3-newhelpticket-aspx.aspx) but it says that page no longer exists. So could you please do me a favor by letting me know if there is any other similar solution page or enlighten the solution by another post.

Thanks in advance,

       Ba Nyar

Free Windows Admin Tool Kit Click here and download it now
March 26th, 2012 6:07am

I had the same problem,then i changed the value of identity element in system.web, and now it works fine.thanks for this article.

<system.web> 
<authentication mode="Windows"/>
<identity impersonate="true" />
</system.web>


August 20th, 2014 3:56am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics