使用手动设置凭据时,EWS 自动发现停止工作
我遇到了一个非常奇怪的问题,我确信这只是我忽略的一些愚蠢的事情。使用 EWS 托管 API,我尝试连接到邮箱以读取联系人。最初,我使用默认凭据,在这种情况下自动发现有效。问题是,稍后我们想在服务器上运行它并模拟用户,所以我通过手动指定凭据来更改它。即使使用我自己的凭据,这个问题也被打破了。
例如,这有效:
service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.AutodiscoverUrl("[email protected]", redirect => true);
这没有:
service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = false;
service.Credentials = new NetworkCredential("user", "pass", "EXAMPLE_DOMAIN");
service.AutodiscoverUrl("[email protected]", redirect => true);
给定的网络凭据应该与默认凭据完全相同,但是在启用跟踪时,我在第二种情况下得到响应“401 Unauthorized”,因此它不充当如果是一样的话。
我缺少什么?
I am running into a very strange issue and I am convinced it is just something stupid that I am overlooking. Using the EWS managed API, I try to connect to a mailbox to read the contacts. Originally, I used the default credentials, in which case the auto discovery worked. The problem is that later on we want to run this on a server and impersonate a user, so I changed it by manually specifying the credentials. This then broke, even when using my own credentials.
As an example, this worked:
service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.AutodiscoverUrl("[email protected]", redirect => true);
This did not:
service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = false;
service.Credentials = new NetworkCredential("user", "pass", "EXAMPLE_DOMAIN");
service.AutodiscoverUrl("[email protected]", redirect => true);
The given network credentials should be exactly the same as the default credentials, but when enabling the tracing, I get the response "401 Unauthorized" in the second case, so it is not acting as if it is the same.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,看来您需要使用
WebCredential("user", "pass", "EXAMPLE_DOMAIN")
。我不太确定为什么WebCredentials
有效,但NetworkCredentials
无效。Ok, it seems that you need to use
WebCredential("user", "pass", "EXAMPLE_DOMAIN")
. I am not exactly sure whyWebCredentials
work butNetworkCredentials
does not.