/// <summary>
        /// Retrieves the selected metadata (in search result listbox) from CSW catalog. Exception shall be thrown.
        /// </summary>
        /// <remarks>
        /// Called in View Metadata, Download Metadata, and Add to Map
        /// </remarks>
        /// <returns>A XMLDocument object if metadata was retrieved successfully. Null if otherwise.</returns>
        private void RetrieveAddToMapInfoFromCatalog()
        {
            try
            {
                // validate
                if (cmbCswCatalog.SelectedIndex == -1)
                {
                    MessageBox.Show(resourceManager.GetString("catalogNotSelected"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (lstSearchResults.SelectedIndex == -1) { throw new Exception(resourceManager.GetString("searchNotSelected")); }
                CswCatalog catalog = (CswCatalog)cmbCswCatalog.SelectedItem;
                if (catalog == null) { throw new NullReferenceException(resourceManager.GetString("catalogNotSpecified")); }
                CswRecord record = (CswRecord)lstSearchResults.SelectedItem;
                if (record == null) throw new NullReferenceException(resourceManager.GetString("searchNotSelected"));

                // connect to catalog if needed
                if (!catalog.IsConnected())
                {
                    string errMsg = "";
                    try { catalog.Connect(); }
                    catch (Exception ex) { errMsg = ex.Message; }

                    // exit if still not connected
                    if (!catalog.IsConnected())
                    {
                        MessageBox.Show(resourceManager.GetString("catalogConnectFailed"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                CswSearchRequest searchRequest = new CswSearchRequest();
                searchRequest.Catalog = catalog;
                try
                {
                    searchRequest.GetAddToMapInfoByID(record.ID);
                    _mapServerUrl = searchRequest.GetMapServerUrl();

                }
                catch (Exception ex)
                {
                    FormMessageBox frmMessageBox = new FormMessageBox();
                    frmMessageBox.Init("Failed to retrieve metadata from service: " + ex.Message,
                                        "Response from CSW service:\r\n" + searchRequest.GetResponse().ResponseXML,
                                        "Error");
                    frmMessageBox.ShowDialog(this);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(resourceManager.GetString("loadXMLException"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }