/// <summary>
        /// Merge the include metadata with current.
        /// </summary>
        /// <returns></returns>
        private string getAndMergeExternalSchema()
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(this.MetadataDocument);

            XmlNode dataServices = xmlDoc.SelectSingleNode("/*[local-name()='Edmx']/*[local-name()='DataServices']");

            string      xpath             = "/*[local-name()='Edmx']/*[local-name()='Reference']";
            XmlNodeList referenceNodeList = xmlDoc.SelectNodes(xpath);

            foreach (XmlNode reference in referenceNodeList)
            {
                if (reference.Attributes["Uri"] != null)
                {
                    try
                    {
                        Uri    referenceUri  = new Uri(reference.Attributes["Uri"].Value, UriKind.RelativeOrAbsolute);
                        var    payload       = XElement.Parse(this.MetadataDocument);
                        string baseUriString = payload.GetAttributeValue("xml:base", ODataNamespaceManager.Instance);
                        if (!string.IsNullOrEmpty(baseUriString) && Uri.IsWellFormedUriString(reference.Attributes["Uri"].Value, UriKind.Relative))
                        {
                            Uri referenceUriRelative = new Uri(reference.Attributes["Uri"].Value, UriKind.Relative);
                            Uri baseUri = new Uri(baseUriString, UriKind.Absolute);
                            referenceUri = new Uri(baseUri, referenceUriRelative);
                        }

                        Response response = WebHelper.Get(referenceUri, string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, this.RequestHeaders);
                        if (response != null && response.StatusCode.Value == System.Net.HttpStatusCode.OK && !string.IsNullOrEmpty(response.ResponsePayload))
                        {
                            XmlDocument referenceDoc = new XmlDocument();
                            referenceDoc.LoadXml(response.ResponsePayload);
                            XmlNodeList referencedSchemas = referenceDoc.SelectNodes("/*[local-name()='Edmx']/*[local-name()='DataServices']/*[local-name()='Schema']");
                            merge(dataServices, referencedSchemas, reference);
                        }
                    }
                    // if one reference doc failed, we should continue merging others.
                    catch (ArgumentException)
                    { continue; }
                    catch (UriFormatException)
                    { continue; }
                    catch (XmlException)
                    { continue; }
                    catch (OversizedPayloadException)
                    { continue; }
                }
            }

            return(xmlDoc.OuterXml);
        }