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("[email protected]", 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.
Autodiscover works for client applications inside and outside firewalls and in resource forest and multiple forest scenarios. For EWS clients, Autodiscover is typically used to find the EWS endpoint URL, but Autodiscover can also provide information to configure clients that use other protocols.
Find autodiscover URL with PowerShell Get the configured autodiscover URL on the Exchange Servers. Run Exchange Management Shell as administrator and run the Get-ClientAccessServer cmdlet. The output will show all the Exchange Servers, including the autodiscover URL (AutoDiscoverServiceInternalUri). That's it!
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("[email protected]", RedirectionUrlValidationCallback);//Throw an exception
And add the uri of the .asmx EWS :
service.Url = new Uri("https://IP/EWS/Exchange.asmx");
The following 3 lines worked for me:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("<loginID..not email address>", "< the pw>");
service.AutodiscoverUrl("<your emailaddress>",RedirectionUrlValidationCallback);
If your login id is abc123. that's good enough. i need specify the domain
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With