static void Main(string[] args) { // Parse the command line. CommandLineArgs arguments = new CommandLineArgs(args); if (!arguments.IsValid) { // Print help and exit. PrintUsage(); return; } // Output to console is copied to AutodiscoverSample.log. Tracing.InitalizeLog(".\\AutodiscoverSample.log"); Tracing.WriteLine("Performing {0} Autodiscover for {1}.", arguments.UseSoapAutodiscover ? "SOAP" : "POX", arguments.EmailAddress); if (!string.IsNullOrEmpty(arguments.AuthenticateAsUser)) { Tracing.WriteLine("Authenticating as " + arguments.AuthenticateAsUser); } SecureString password = GetPasswordFromConsole(); if (password.Length == 0) { return; } NetworkCredential userCredentials = new NetworkCredential(string.IsNullOrEmpty(arguments.AuthenticateAsUser) ? arguments.EmailAddress : arguments.AuthenticateAsUser, password); // Create the request. AutodiscoverRequest autodiscoverRequest = new AutodiscoverRequest(arguments.EmailAddress, userCredentials); // Start the Autodiscover process. Dictionary <string, string> userSettings = autodiscoverRequest.DoAutodiscover(arguments.UseSoapAutodiscover); // If the process succeeded, print out the returned settings. if (userSettings != null) { Tracing.WriteLine("Settings:"); foreach (KeyValuePair <string, string> setting in userSettings) { Tracing.WriteLine(" {0}: {1}", setting.Key, setting.Value); } } else { Tracing.WriteLine("No settings returned."); } Tracing.WriteLine("Finished."); Tracing.FinalizeLog(); Console.WriteLine("\nHit any key to exit..."); Console.ReadKey(); }
//static void PrintExchangeVersion(string mailBox, string userName, string password) //{ // NetworkCredential ncCred = new NetworkCredential(UserName, Password); // String EWSURL = null; // String EWSVersion = null; // AutodiscoverService asAutodiscoverService = new AutodiscoverService(); // asAutodiscoverService.Credentials = ncCred; // asAutodiscoverService.EnableScpLookup = false; // asAutodiscoverService.RedirectionUrlValidationCallback = RedirectionUrlValidationCallback; // UserSettingName[] unUserSettings = new UserSettingName[2] { UserSettingName.ExternalEwsUrl, UserSettingName.ExternalEwsVersion }; // GetUserSettingsResponse adResponse = asAutodiscoverService.GetUserSettings(MbMailbox, unUserSettings); // EWSURL = (String)adResponse.Settings[UserSettingName.ExternalEwsUrl]; // EWSVersion = (String)adResponse.Settings[UserSettingName.ExternalEwsVersion]; //} static void Main(string[] args) { Console.WriteLine("Please input test mailbox address:"); string mailAddress = Console.ReadLine(); Console.WriteLine("Please input user name with Domain:"); string user = Console.ReadLine(); bool isUseSOAP = false; // Parse the command line. //CommandLineArgs arguments = new CommandLineArgs(args); //if (!arguments.IsValid) //{ // // Print help and exit. // PrintUsage(); // return; //} // Output to console is copied to AutodiscoverSample.log. Tracing.InitalizeLog(".\\AutodiscoverSample.log"); Tracing.WriteLine("Performing {0} Autodiscover for {1}.", //arguments.UseSoapAutodiscover ? "SOAP" : "POX", isUseSOAP ? "SOAP" : "POX", //arguments.EmailAddress); "*****@*****.**"); //if (!string.IsNullOrEmpty(arguments.AuthenticateAsUser)) if (!string.IsNullOrEmpty(user)) { //Tracing.WriteLine("Authenticating as " + arguments.AuthenticateAsUser); Tracing.WriteLine("Authenticating as " + user); } SecureString password = GetPasswordFromConsole(); if (password.Length == 0) return; //NetworkCredential userCredentials = new NetworkCredential(string.IsNullOrEmpty(arguments.AuthenticateAsUser) ? // arguments.EmailAddress : arguments.AuthenticateAsUser, password); NetworkCredential userCredentials = new NetworkCredential(string.IsNullOrEmpty(user) ? mailAddress : user, password); // Create the request. //AutodiscoverRequest autodiscoverRequest = new AutodiscoverRequest(arguments.EmailAddress, AutodiscoverRequest autodiscoverRequest = new AutodiscoverRequest(mailAddress, userCredentials); // Start the Autodiscover process. Dictionary<string, string> userSettings = autodiscoverRequest.DoAutodiscover(isUseSOAP); // If the process succeeded, print out the returned settings. if (userSettings != null) { Tracing.WriteLine("Settings:"); foreach (KeyValuePair<string, string> setting in userSettings) { Tracing.WriteLine(" {0}: {1}", setting.Key, setting.Value); } } else { Tracing.WriteLine("No settings returned."); } Tracing.WriteLine("Finished."); Tracing.FinalizeLog(); Console.WriteLine("\nHit any key to exit..."); Console.ReadKey(); }