/// <summary>
        /// Point of access to the application.
        /// </summary>
        /// <param name="xmlRequest">The message with the request in XML format</param>
        public string XMLRequest(string xmlRequest)
        {
            // Start Time
            DateTime lStartTime = DateTime.Now;

            // Response Type
            string lResponseType = "Service.Response";

            // Request Attributes
            string lSecuence           = "";
            string lDTDVersionResponse = "";
            double lDTDVersion         = 0;

            try
            {
                // Create XMLReader
                XmlTextReader lXMLReader = new XmlTextReader(new StringReader(xmlRequest));
                lXMLReader.WhitespaceHandling = WhitespaceHandling.None;
                lXMLReader.MoveToContent();

                // Read Attributes
                string lApplication = lXMLReader.GetAttribute("Application");
                string lIdCnx       = lXMLReader.GetAttribute("IdCnx");
                lSecuence   = lXMLReader.GetAttribute("Sequence");
                lDTDVersion = ExtractDTDVersion(lXMLReader.GetAttribute("VersionDTD"));
                if (lDTDVersion >= 3.0)
                {
                    lDTDVersionResponse = "CARE.Response v. " + lDTDVersion.ToString("#.00", ONXml.ComXMLFormat);
                }
                else
                {
                    lDTDVersionResponse = "CARE.Response v." + lDTDVersion.ToString("#.0", ONXml.ComXMLFormat);
                }
                lXMLReader.ReadStartElement("Request");

                // Check Secure server
                if ((ONSecureControl.SecureServer) && (lDTDVersion < 3.1))
                {
                    throw new ONAgentValidationException(null);
                }

                // Create XMLWriter
                MemoryStream  lXMLMemoryStream = new MemoryStream();
                XmlTextWriter lXMLWriter       = new XmlTextWriter(lXMLMemoryStream, new System.Text.UTF8Encoding());
                lXMLWriter.WriteStartDocument();

                // Create XMLWriterRequest
                XmlTextWriter lXMLWriterRequest = null;

                // Load agent
                ONOid  lAgentOID = GetAgent(lXMLReader, lDTDVersion);
                string lTicket   = "";
                if (lDTDVersion >= 3.1)
                {
                    lTicket = GetTicket(lXMLReader, lDTDVersion);
                }

                lStartTime = DateTime.Now;
                if (lXMLReader.IsStartElement("Service.Request"))
                {
                    string lService = lXMLReader.GetAttribute("Service");
                    if ((lDTDVersion >= 3.1) && (string.Compare(lService, "MVAgentValidation", true) != 0))
                    {
                        using (ONContext lOnContext = new ONContext())
                        {
                            if (((object)lAgentOID == null) || !lAgentOID.IsAnonymousAgent)
                            {
                                ONOid lAgentOid = lOnContext.SetTicket(lDTDVersion, lApplication, lTicket);
                                if (ONSecureControl.SecureServer)
                                {
                                    if (lAgentOID != lAgentOid)
                                    {
                                        throw new ONAgentValidationException(null);
                                    }
                                }
                            }
                        }
                    }

                    // Response Type
                    lResponseType = "Service.Response";

                    // Read Attributes
                    string lClass = lXMLReader.GetAttribute("Class");

                    // Global services
                    if ((lClass == "") || (lClass == "InteraccionGlobal") || (lClass == "GlobalTransactions"))
                    {
                        lClass = "GlobalTransaction";
                    }

                    ONXml lComponent = ONContext.GetComponent_XML(lClass);
                    lComponent.XMLRequestService(ref lTicket, lAgentOID, lXMLReader, out lXMLWriterRequest, lDTDVersion, lApplication);
                }
                else if (lXMLReader.IsStartElement("Query.Request"))
                {
                    if (lDTDVersion >= 3.1)
                    {
                        using (ONContext lOnContext = new ONContext())
                        {
                            if (((object)lAgentOID == null) || !lAgentOID.IsAnonymousAgent)
                            {
                                ONOid lAgentOid = lOnContext.SetTicket(lDTDVersion, lApplication, lTicket);
                                if (ONSecureControl.SecureServer)
                                {
                                    if (lAgentOID != lAgentOid)
                                    {
                                        throw new ONAgentValidationException(null);
                                    }
                                }
                            }
                        }
                    }

                    // Response Type
                    lResponseType = "Query.Response";

                    // Read Attributes
                    string lClass = lXMLReader.GetAttribute("Class");

                    ONXml lComponent = ONContext.GetComponent_XML(lClass);
                    lComponent.XMLRequestQuery(ref lTicket, lAgentOID, lXMLReader, out lXMLWriterRequest, lDTDVersion, lApplication);
                }
                else
                {
                    throw new ONXMLException(null, "Request type");
                }

                // Get Time
                DateTime lEndTime     = DateTime.Now;
                double   lElapsedTime = (lEndTime.Ticks - lStartTime.Ticks) / 10000;

                // Write Response
                lXMLWriter.WriteStartElement("Response");
                lXMLWriter.WriteAttributeString("Sequence", lSecuence);
                lXMLWriter.WriteAttributeString("VersionDTD", lDTDVersionResponse);

                lXMLWriter.WriteStartElement("Statistics");
                lXMLWriter.WriteAttributeString("StartTime", lStartTime.ToString().Trim());
                lXMLWriter.WriteAttributeString("EndTime", lEndTime.ToString().Trim());
                lXMLWriter.WriteAttributeString("ElapsedTime", lElapsedTime.ToString().Trim());
                lXMLWriter.WriteEndElement();                 // Statistics

                if (lDTDVersion >= 3.1)
                {
                    lXMLWriter.WriteElementString("Ticket", lTicket);
                }

                // Write Query / Service XML
                MemoryStream lXMLMemoryStreamRequest = lXMLWriterRequest.BaseStream as MemoryStream;
                lXMLWriter.Flush();
                lXMLWriterRequest.Flush();
                lXMLMemoryStreamRequest.Flush();
                lXMLMemoryStreamRequest.Position = 0;
                lXMLMemoryStreamRequest.WriteTo(lXMLMemoryStream);

                lXMLWriter.WriteEndElement();                 // Response

                // Get Response
                lXMLWriter.Flush();
                lXMLMemoryStream.Flush();
                lXMLMemoryStream.Position = 0;
                StreamReader lXMLStreamReader = new StreamReader(lXMLMemoryStream);
                string       lResponse        = lXMLStreamReader.ReadToEnd();

                // Close Writer
                lXMLWriterRequest.Close();
                lXMLWriter.Close();

                // Close Reader
                lXMLReader.Close();
                return(lResponse);
            }
            catch (Exception e)
            {
                // Create XMLWriter
                MemoryStream  lXMLMemoryStream = new MemoryStream();
                XmlTextWriter lXMLWriter       = new XmlTextWriter(lXMLMemoryStream, new System.Text.UTF8Encoding());
                lXMLWriter.WriteStartDocument();

                // Write Response
                lXMLWriter.WriteStartElement("Response");
                lXMLWriter.WriteAttributeString("Sequence", lSecuence);
                lXMLWriter.WriteAttributeString("VersionDTD", lDTDVersionResponse);

                // Get Time
                DateTime lEndTime     = DateTime.Now;
                double   lElapsedTime = (lEndTime.Ticks - lStartTime.Ticks) / 10000;

                // Write Statistics
                lXMLWriter.WriteStartElement("Statistics");
                lXMLWriter.WriteAttributeString("StartTime", lStartTime.ToString().Trim());
                lXMLWriter.WriteAttributeString("EndTime", lEndTime.ToString().Trim());
                lXMLWriter.WriteAttributeString("ElapsedTime", lElapsedTime.ToString().Trim());
                lXMLWriter.WriteEndElement();                 // Statistics

                // Write ServiceResponse / QueryResponse
                lXMLWriter.WriteStartElement(lResponseType);
                if (lDTDVersion > 2)
                {
                    if (e is ONException)
                    {
                        ONXml.CreateXMLError(lXMLWriter, e as ONException, lDTDVersion);
                    }
                    else
                    {
                        lXMLWriter.WriteStartElement("Error");
                        lXMLWriter.WriteAttributeString("Type", "Model");
                        lXMLWriter.WriteAttributeString("Number", "999");
                        lXMLWriter.WriteElementString("Error.Message", "");
                        lXMLWriter.WriteElementString("Error.Params", "");
                        lXMLWriter.WriteElementString("Error.Trace", "");
                        lXMLWriter.WriteEndElement();                         // Error
                    }
                }
                else
                {
                    lXMLWriter.WriteStartElement("Error");
                    lXMLWriter.WriteAttributeString("Type", "External");
                    lXMLWriter.WriteAttributeString("Number", "999");
                    lXMLWriter.WriteString(e.Message);
                    lXMLWriter.WriteEndElement();             // Error
                }
                lXMLWriter.WriteEndElement();                 // Service.Response / Query.Response

                // Write Response
                lXMLWriter.WriteEndElement();                 // Response

                // Get Response
                lXMLWriter.Flush();
                lXMLMemoryStream.Flush();
                lXMLMemoryStream.Position = 0;
                StreamReader lXMLStreamReader = new StreamReader(lXMLMemoryStream);
                string       lResponse        = lXMLStreamReader.ReadToEnd();

                // Close Writer
                lXMLWriter.Close();

                return(lResponse);
            }
        }