1

I have written a windows service in C# to automatically poll an exchange mailbox using EWS.

On my development machine, which is connected to the exchange server network via VPN, it works perfectly.

On the target server the EWS is returning:

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

On the same server, I can connect to the EWS URL via a browser using the same credentials as are being provided to the service.

The credentials are provided in the app.config file, and I have triple checked that they are the same on the target server as my development machine.

What could be causing this?

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Dale K
  • 25,246
  • 15
  • 42
  • 71

1 Answers1

0

Well as it turned out the issue was that this

_ews.Credentials = new NetworkCredential(Settings.Username, Settings.Password); // Username in the form "domainname\username"

should have been this

_ews.Credentials = new NetworkCredential(Settings.Username, Settings.Password, Settings.Domain); // Domainname and username separate

For some reason the first line worked externally over a VPN but not internally on the domain network itself.

Dale K
  • 25,246
  • 15
  • 42
  • 71