3

Creating a web page that will connect to Exchange Web service and retrieve current user's Inbox items. The authentication needs to be integrated. We don't want anyone to login.

Configured IIS to do Windows Authentication and set below parameters in web.config.

This got it working but only if the website is called on the server where it's hosted. If I call the same exact URL on another workstation, I get (401) Unauthorized.

If the page correctly authenticates itself against exchange when executed on the host server, why doesn't the same thing work when the same page is called from client workstation? The windows/domain logon user id is the same in both cases. Below is how the code authenticates against Exchange.

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Url = new Uri("https://hostname/EWS/Exchange.asmx");
service.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

Does anyone have an idea of what could be the culprit here? Thanks!

MLofNY
  • 31
  • 2
  • possible duplicate of [Exchange Web Service API and 401 unauthorized exception](http://stackoverflow.com/questions/13517323/exchange-web-service-api-and-401-unauthorized-exception) – Shadow The GPT Wizard May 25 '14 at 08:07

2 Answers2

0

Try using:

service.Credentials = new WebCredentials("user", "passwordd", "domain");

It should work.

Carlos Landeras
  • 11,025
  • 11
  • 56
  • 82
0

(401) Unauthorized error means you are not able to to log in, because of wrong username and password. you should try like this

        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
        service.Credentials = new NetworkCredential(username, password);
        service.TraceEnabled = true;


        service.Url = new Uri("https://hostname/EWS/Exchange.asmx");
        ExportMIMEEmail(service, count); //call to export mails;

above code is working for me

Vikas Lalwani
  • 1,041
  • 18
  • 29