Пример #1
0
        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);
        }
Пример #2
0
        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();
        }
Пример #3
0
        protected override void HandleResponse(AutodiscoverResponse autodiscoverResponse)
        {
            GetDomainSettingsResponse getDomainSettingsResponse = (GetDomainSettingsResponse)autodiscoverResponse;

            if (getDomainSettingsResponse.DomainResponses == null || getDomainSettingsResponse.DomainResponses.Length != base.EmailAddresses.Length)
            {
                SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceError <DomainSoapAutoDiscoverRequest>((long)this.GetHashCode(), "{0}: Response with no DomainResponses or unexpected number of DomainResponses", this);
                this.HandleException(new AutoDiscoverFailedException(Strings.descSoapAutoDiscoverInvalidResponseError(this.client.Url), 63804U));
                return;
            }
            SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <DomainSoapAutoDiscoverRequest>((long)this.GetHashCode(), "{0}: Received valid response.", this);
            AutoDiscoverRequestResult[] array = new AutoDiscoverRequestResult[base.EmailAddresses.Length];
            for (int i = 0; i < base.EmailAddresses.Length; i++)
            {
                array[i] = this.GetAutodiscoverResultFromDomainResponse(base.EmailAddresses[i], getDomainSettingsResponse.DomainResponses[i]);
            }
            base.HandleResult(array);
        }