MLofNY
MLofNY

Reputation: 31

401 error while calling Exchange Web Service

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!

Upvotes: 3

Views: 1984

Answers (2)

Vikas Lalwani
Vikas Lalwani

Reputation: 1061

(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

Upvotes: 0

Carlos Landeras
Carlos Landeras

Reputation: 11063

Try using:

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

It should work.

Upvotes: 0

Related Questions