EWS 401 Unauthorized - But only when running under a service on the target server

折月煮酒 提交于 2019-12-08 08:32:15

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/18476472/ews-401-unauthorized-but-only-when-running-under-a-service-on-the-target-serve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!