public string GetDomainSettings( ) //public string GetDomainSettings(string sServerDomain, string sUser, string sPassword, string sDomain, ExchangeVersion oExchangeVersion) { // https://msdn.microsoft.com/en-us/library/office/jj900161(v=exchg.150).aspx string sRet = string.Empty; AutodiscoverService autodiscoverService = new AutodiscoverService("domain.contoso.com"); autodiscoverService.Credentials = new NetworkCredential("User1", "password", "domain.contoso.com"); // Submit a request and get the settings. The response contains only the // settings that are requested, if they exist. GetDomainSettingsResponse domainresponse = autodiscoverService.GetDomainSettings( "domain", ExchangeVersion.Exchange2013, DomainSettingName.ExternalEwsUrl, DomainSettingName.ExternalEwsVersion); // Display each retrieved value. The settings are part of a key/value pair. foreach (KeyValuePair <DomainSettingName, Object> domainsetting in domainresponse.Settings) { Console.WriteLine(domainsetting.Key.ToString() + ": " + domainsetting.Value.ToString()); } // Console.WriteLine(domainresponse.Settings[DomainSettingName.ExternalEwsUrl]); return(sRet); }
private void GoRun_Click(object sender, EventArgs e) { bool bError = false; StringBuilder oSB = new StringBuilder(); AutodiscoverService autodiscoverService = new AutodiscoverService(TargetMailDomain.Text.Trim(), this.exchangeVersionCombo.SelectedItem.Value); autodiscoverService.UseDefaultCredentials = this.chkDefaultWindowsCredentials.Checked; if (this.chkDefaultWindowsCredentials.Checked == false) { if (txtUser.Text.Trim().Length != 0 || txtUser.Text.Trim().Length != 0) { if (txtDomain.Text.Trim().Length == 0) { autodiscoverService.Credentials = new NetworkCredential(txtUser.Text.Trim(), txtPassword.Text.Trim()); } else { autodiscoverService.Credentials = new NetworkCredential(txtUser.Text.Trim(), txtPassword.Text.Trim(), txtDomain.Text.Trim()); } } else { MessageBox.Show("Uer ID and Password need to be set at a mimum."); } } if (bError == false) { // Submit a request and get the settings. The response contains only the // settings that are requested, if they exist. GetDomainSettingsResponse domainresponse = autodiscoverService.GetDomainSettings( TargetMailDomain.Text.Trim(), this.exchangeVersionCombo.SelectedItem.Value, DomainSettingName.ExternalEwsUrl, DomainSettingName.ExternalEwsVersion); // Display each retrieved value. The settings are part of a key value pair. foreach (KeyValuePair <DomainSettingName, Object> domainsetting in domainresponse.Settings) { oSB.AppendLine(domainsetting.Key.ToString() + ": " + domainsetting.Value.ToString()); } } txtResults.Text = oSB.ToString(); }