0

Tried everything I've found and keep getting this error using AutodiscoverUrl call on EWS service.

have tried supplying webcredentials, networkcredentials, and none. If I set the service.Url property myself then it works. I can access EWS calls no problem.

This is the call stack when it errors.

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.

I have also checked I can ping the Exchange server via dns entry autodiscover. I've checked the AD for the SCP and it looks ok. Outlook can find the Autodiscover no problems. Only my code can't.

In case it matters, all of my machines are Azure vm's on a virtual subnet.

My code:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.AutodiscoverUrl("Lyynx@ocean.lythixdesigns.com"); // Exception is thrown here
Stephen Price
  • 1,629
  • 1
  • 24
  • 42
  • Two things you could try is firstly enable tracing which will provide more information then the stacktrace. The other thing is test your Autodiscover config using https://testconnectivity.microsoft.com/ – Glen Scales Sep 22 '14 at 05:26
  • I enabled the tracing and it does not even call the tracer. I verified the tracer is working by tracing it with the working code. I looked at the test page you shared but I'd need to work out how to get it to work over Internet right? Or does that page work on intranet? Will have another look at it – Stephen Price Sep 22 '14 at 10:22
  • No that won't work over an Intranet you have to have Autodiscover exposed externally which is generally the case for most people (else Activesync etc won't work). Another test would be try the http://ewseditor.codeplex.com/ this will allow you to test the Managed API and EWS outside of your code. – Glen Scales Sep 22 '14 at 22:49
  • Handy tool. I downloaded it and ran on my dev vm. InternalEwsUrl: https://mantaray.ocean.lythixdesigns.com/EWS/Exchange.asmx which is the url that I entered that works. – Stephen Price Sep 23 '14 at 03:18
  • Did you try the Autodiscover Viewer ? (from the Tools menu) this will show you a more debug version of the Auto-discover process – Glen Scales Sep 23 '14 at 04:04
  • Yes, that's what I was referring to. The InternalEwsUrl was returned and it showed no errors. So Autodiscover is working, but my code doesn't work. I'm going to get the source for that tool and see exactly how they are calling it. Thanks for the help so far btw – Stephen Price Sep 23 '14 at 08:41
  • I've decompiled the source using reflector and notice an exception deeper in "Additional information: The remote certificate is invalid according to the validation procedure." Also if I browse to the url it's returning (the Autodiscover url) it shows a self signed certificate warning. Perhaps that's the cause. Is there a way to trust it? Will investigate further – Stephen Price Sep 23 '14 at 09:26

1 Answers1

1

After decompiling and debugging the exceptions being thrown, I discovered that due to using a self signed certificate it was not allowing the autodiscover url to be used.

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

This url shows how to copy the certificate into the Trusted Root Certification Authorities folder in Internet Explorer. I ran IE as Administrator and copied it in. My code now works. It hit one more exception saying it was not authenticated but I think that's where it then uses the log in credentials.

So trusting the certificate was the answer to my issue.

Stephen Price
  • 1,629
  • 1
  • 24
  • 42