/// <summary>
        /// Write autodiscover response to console.
        /// </summary>
        /// <param name="response"></param>

        void WriteResponse(AutodiscoverRaw.AutodiscoverResponseXml response)
        {
            WriteValue("");
            WriteValue("+ Response Results");
            WriteValue("");
            if (response != null)
            {
                if (response.OutlookData != null)
                {
                    if (response.OutlookData.User != null)
                    {
                        WriteValue("  User/DisplayName", response.OutlookData.User.DisplayName);
                        WriteValue("  User/LegacyDN", response.OutlookData.User.LegacyDN);
                        WriteValue("  User/DeploymentId", response.OutlookData.User.DeploymentId);
                    }

                    if (response.OutlookData.Account != null)
                    {
                        WriteValue("  Account/AccountType", response.OutlookData.Account.AccountType);
                        WriteValue("  Account/Action", response.OutlookData.Account.Action);
                        WriteValue("  Account/AuthPackage", response.OutlookData.Account.AuthPackage);
                        WriteValue("  Account/RedirectAddr", response.OutlookData.Account.RedirectAddr);
                        WriteValue("  Account/SSL", response.OutlookData.Account.SSL);

                        if (response.OutlookData.Account.Protocol != null)
                        {
                            foreach (AutodiscoverRaw.ProtocolXml protocolXml in response.OutlookData.Account.Protocol)
                            {
                                WriteValue("  Account/Protocol/Type", protocolXml.Type);
                                WriteValue("  Account/Protocol/ASUrl", protocolXml.ASUrl);
                                WriteValue("  Account/Protocol/AuthPackage", protocolXml.AuthPackage);
                                WriteValue("  Account/Protocol/CertPincipalName", protocolXml.CertPrincipalName);
                                WriteValue("  Account/Protocol/DirectoryPort", protocolXml.DirectoryPort);
                                WriteValue("  Account/Protocol/FBPublish", protocolXml.FBPublish);
                                WriteValue("  Account/Protocol/MdbDN", protocolXml.MdbDN);
                                WriteValue("  Account/Protocol/OABUrl", protocolXml.OABUrl);
                                WriteValue("  Account/Protocol/OOFUrl", protocolXml.OOFUrl);
                                WriteValue("  Account/Protocol/Port", protocolXml.Port);
                                WriteValue("  Account/Protocol/ReferralPort", protocolXml.ReferralPort);
                                WriteValue("  Account/Protocol/Server", protocolXml.Server);
                                WriteValue("  Account/Protocol/ServerDN", protocolXml.ServerDN);
                                WriteValue("  Account/Protocol/ServerVersion", protocolXml.ServerVersion);
                                WriteValue("  Account/Protocol/SSL", protocolXml.SSL);
                                WriteValue("  Account/Protocol/TTL", protocolXml.TTL);
                                WriteValue("  Account/Protocol/UMUrl", protocolXml.UMUrl);

                                if (protocolXml.OtherXml != null)
                                {
                                    foreach (object otherXml in protocolXml.OtherXml)
                                    {
                                        WriteXmlNode("  Account/Protocol", otherXml as System.Xml.XmlNode);
                                    }
                                }
                            }
                        }
                    }
                }

                if ((response.ErrorResponse != null) && (response.ErrorResponse.Error != null))
                {
                    WriteValue("-------------------------------------------------------");
                    WriteValue("!! Errors: ");
                    WriteValue("-------------------------------------------------------");
                    WriteValue("    Error/ErrorCode", response.ErrorResponse.Error.ErrorCode);
                    WriteValue("    Error/Message", response.ErrorResponse.Error.Message);
                    WriteValue("    Error/DebugData", response.ErrorResponse.Error.DebugData);
                    WriteValue("    Error/Id", response.ErrorResponse.Error.Id);
                    WriteValue("    Error/Time", response.ErrorResponse.Error.Time);
                    WriteValue("-------------------------------------------------------");
                    WriteValue("");
                }
            }
            WriteValue("");
            WriteValue("- Response Results");
            WriteValue("");
        }
        private bool DoAutoDiscoverRaw(
            DiscoverType oDiscoverType,
            ref InMemoryListener oIML,
            string sEmail,
            NetworkCredential oNetworkCredential,
            int iMaxHops,
            bool bAllowSelfSignedCerts,
            bool bTraceCertificateInformation
            )
        {
            bool bRet = false;

            try
            {
                // Identifies the maximum number of redirections through either SCP pointer or Autodiscover redirects.

                AutodiscoverRaw oAutodiscoverRaw = new AutodiscoverRaw();
                AutodiscoverRaw.AutodiscoverResponseXml response = null;

                if (oDiscoverType == DiscoverType.Scp)
                {
                    // Call Autodiscover service.
                    response =
                        oAutodiscoverRaw.DiscoverScp(
                            ref oIML,
                            sEmail,
                            oNetworkCredential,
                            ref iMaxHops,
                            bAllowSelfSignedCerts,
                            bTraceCertificateInformation
                            );
                }

                if (oDiscoverType == DiscoverType.Pox)
                {
                    // Call Autodiscover service.
                    response =
                        oAutodiscoverRaw.DiscoverPox(
                            ref oIML,
                            sEmail,
                            oNetworkCredential,
                            ref iMaxHops,
                            bAllowSelfSignedCerts,
                            bTraceCertificateInformation
                            );
                }

                if (oDiscoverType == DiscoverType.Soap)
                {
                    // Call Autodiscover service.
                    //string sUrl = string.Empty;
                    response =
                        oAutodiscoverRaw.TryDiscoverSoap(
                            ref oIML,
                            sEmail,
                            oNetworkCredential,
                            ref iMaxHops,
                            bAllowSelfSignedCerts,
                            bTraceCertificateInformation
                            );
                    //if (sUrl == string.Empty)
                    //    response =  false;
                    //else
                    //    response = true;
                }

                // Write response to console.
                WriteResponse(response);

                bRet = true;
            }
            catch (System.Exception e)
            {
                oIML.WriteLine("Error: " + e.ToString());
                //MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                //System.Console.WriteLine(e.ToString());
                bRet = false;
            }

            return(bRet);
        }