简体   繁体   中英

EWS The Autodiscover service couldn't be located

I'm using C# EWS (ExchangeWebServices).
I have ExchangeServer ie 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");

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

On my machine (win7), I can find it here: Control Panel - System - Computer name, domain and workgroup settings. Maybe you can have a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM