我正在创建一个C#.NET桌面应用程序,它使用EWS与我们组织的本地托管Exchange服务器进行交互 . 我的应用程序在进行身份验证时使用用户的默认(域)凭据 . 没有额外的auth / 2步骤 . 到目前为止,这没有任何问题 .

var exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP2)
{
    UseDefaultCredentials = true,
    Url = new Uri(_exchangeUrl),
    TraceEnabled = true,
};

我们的大多数网络计算机都使用代理连接到Internet . 启用代理后,我的应用程序在使用EWS进行身份验证时没有问题 . 禁用代理后,我们发现服务器返回401 Unauthorized响应 . 我的网络管理员告诉我,每个日志的用户名似乎都是空白的 .

奇怪的是,虽然代理被禁用(在同一台计算机上),但使用PowerShell与EWS交互似乎仍然有效,但使用C#应用程序失败了 .

Import-Module -Name ".\Microsoft.Exchange.WebServices.dll"
$exchangeService = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService -ArgumentList 'Exchange2010_SP2'
$exchangeService.UseDefaultCredentials = 1
$exchangeService.TraceEnabled = 1
$exchangeService.Url = "blah same url"

我的Exchange管理员认为EWS路由已正确配置 . 所以,我们有点亏 . 这有点像网络跳跃问题,但我们无法解释为什么PowerShell继续工作 .

我确实比较了C#和PowerShell的跟踪输出,并且发现“跟踪”标记中的“Tid”和“Time”属性没有区别 .

还有什么我们可以检查的吗?