问题
I have code to send email using Exchange Web Services (EWS 1.1 API). There is no exception if I use the hardcoded parameter values, like:
service.AutodiscoverUrl("me@mydomain.com",
delegate
{
return true;
});
But If I try to use a variable then I am getting error while discovering URL, "The Autodiscover service couldn't be located".
string userName = "me@mydomain.com";
service.AutodiscoverUrl(userName,
delegate
{
return true;
});
Is there any way to use variables with autodiscoverurl method? What am I doing wrong?
Sanjay
回答1:
It's very unlikely that this is causing the problem. Typically, if AutoDiscover fails, it's because of invalid credentials or network connectivity issues.
Enable tracing on the ExchangeService instance (MSDN article) to see what is going on.
回答2:
I realize this post is a few years old, but I'm offering an additional solution simply for the sake of documentation.
Another possible cause of this behavior is the client is attempting to force a TLS 1.2 connection when the EWS server is supporting only TLS 1.0. I was about to surrender investigating this very behavior - an EWS app worked on one box, and the same app failed on a different box (going to the same mailbox) - and the problem was one machine could negotiate TLS 1.0, which worked, while the other could do TLS 1.2 only, which failed. Enabling client TLS 1.0 outbound connections in the registry (HKLM\System\CCS\Services\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Client
, DWORD value 'Enabled' set to 0x1 fixed the problem. No reboot required.
回答3:
And just to add another solution - I was struggling because of the opposite problem to David W above - my exchange server only supported TLS1.2, but my app (.net 4.5) only supported 1.0 by default.
Fixed by adding:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
to my app startup code. I believe this is enabled by default for .net 4.6 onwards
The specific error I was getting was:
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2018-10-29 15:32:40Z">
failed: WebException (The underlying connection was closed: An unexpected error occurred on a send.)
</Trace>
Exception thrown: 'Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException' in Microsoft.Exchange.WebServices.dll
来源:https://stackoverflow.com/questions/7850890/the-autodiscover-service-couldnt-be-located