自动发现服务无法在C#中找到,但适用于Outlook

时间:2014-09-21 16:02:47

标签: exchangewebservices exchange-server-2013

尝试了我发现的所有内容,并使用EWS服务上的AutodiscoverUrl调用继续收到此错误。

尝试过提供webcredentials,networkcredentials和none。 如果我自己设置service.Url属性,那么它的工作原理。我可以访问EWS电话没问题。

这是错误时的调用堆栈。

A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException'     occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'Microsoft.Exchange.WebServices.Dns.DnsException' occurred in Microsoft.Exchange.WebServices.dll
A first chance exception of type 'Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException' occurred in Microsoft.Exchange.WebServices.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'Microsoft.Exchange.WebServices.Dns.DnsException' occurred in Microsoft.Exchange.WebServices.dll
A first chance exception of type 'Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException' occurred in Microsoft.Exchange.WebServices.dll


An unhandled exception of type 'Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException' occurred in Microsoft.Exchange.WebServices.dll

Additional information: The Autodiscover service couldn't be located.

我还检查过我可以通过dns entry autodiscover ping Exchange服务器。我已经检查了AD的SCP,看起来还不错。 Outlook可以发现自动发现没有问题。只有我的代码不能。

如果重要,我的所有机器都是虚拟子网上的Azure vm。

我的代码:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.AutodiscoverUrl("Lyynx@ocean.lythixdesigns.com"); // Exception is thrown here

1 个答案:

答案 0 :(得分:1)

在反编译和调试抛出的异常后,我发现由于使用自签名证书,它不允许使用自动发现URL。

http://blogs.msdn.com/b/robert_mcmurray/archive/2013/11/15/how-to-trust-the-iis-express-self-signed-certificate.aspx

此网址显示如何将证书复制到Internet Explorer中的“受信任的根证书颁发机构”文件夹中。我以管理员身份运行IE并将其复制进来。我的代码现在可以运行了。它还有一个例外,它说它没有经过身份验证,但我认为这就是它使用登录凭据的地方。

所以相信证书就是我的问题的答案。