I'm using C# EWS (ExchangeWebServices).
I have ExchangeServer i.e with the following IP: 10.81.5.1.
Now, I'm trying to access to ExchangeServer like the follow:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials("myuser", "mypassword", "10.81.5.1");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl("myuser@mydomain.local", RedirectionUrlValidationCallback);//Throw an exception
And I got the following exception:
The Autodiscover service couldn't be located.
How i know my ExchangeServer domain?
When I'm changed the following (and run the code inside the ExchangeServer machine)
service.Credentials = new WebCredentials("myuser", "mypassword");
Meaning the domain is the localhost i'm success to run my code without exception.
What is the mistake at my code?
What i need to write instead "10.81.5.1" if I'm not running the code inside the ExchangeServer machine? How can i know my ExchangeServer "domain"?
Thanks.
The reason of my problem was that the exchange server and my develop machine isn't on the same domain.
Solved by removed the follow line:
service.AutodiscoverUrl("myuser@mydomain.local", RedirectionUrlValidationCallback);//Throw an exception
And add the uri of the .asmx EWS :
service.Url = new Uri("https://IP/EWS/Exchange.asmx");