protected void Button2_Click(object sender, EventArgs e)
        {
            CambioFechaInicial Fechasiniciales = TipoCambioService.InvokeServiceCambioFecha(Calendar1.SelectedDate.Date.ToString("dd/MM/yyyy"));
            string             todasfechas     = "";

            foreach (CambioFechaInicial.Var var in Fechasiniciales.Fechas)
            {
                todasfechas = $"{todasfechas}Fecha: {var.Fecha} Compra: {var.Compra} Venta: {var.Venta}\n";
            }
            DateResultado.Text = todasfechas;
        }
Beispiel #2
0
        public static CambioFechaInicial InvokeServiceCambioFecha(string fecha)
        {
            string fecha_ini = fecha;
            //Calling CreateSOAPWebRequest method
            HttpWebRequest request = CreateSOAPWebRequestCambioFecha();

            XmlDocument SOAPReqBody = new XmlDocument();

            //SOAP Body Request
            SOAPReqBody.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
                <soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
                  <soap:Body>
                    <TipoCambioFechaInicial xmlns=""http://www.banguat.gob.gt/variables/ws/"">
                    <fechainit >" + fecha_ini + @"</fechainit >
                    </TipoCambioFechaInicial >
                  </soap:Body>
                </soap:Envelope>");


            using (Stream stream = request.GetRequestStream())
            {
                SOAPReqBody.Save(stream);
            }
            //Geting response from request

            string xml = "";

            using (WebResponse Serviceres = request.GetResponse())
            {
                using (StreamReader rd = new StreamReader(Serviceres.GetResponseStream()))
                {
                    //reading stream
                    var ServiceResult = rd.ReadToEnd();
                    //writting stream result on console
                    xml += ServiceResult;
                }
            }
            System.Diagnostics.Debug.WriteLine(xml);

            XDocument doc = XDocument.Parse(xml);

            var Vars = doc.Descendants().Where(x => x.Name.LocalName == "Var").Select(y => new {
                fecha  = (string)y.Elements().Where(a => a.Name.LocalName == "fecha").FirstOrDefault(),
                venta  = (string)y.Elements().Where(a => a.Name.LocalName == "venta").FirstOrDefault(),
                compra = (string)y.Elements().Where(a => a.Name.LocalName == "compra").FirstOrDefault(),
            }).ToList();

            var totalitem = doc.Descendants().Where(x => x.Name.LocalName == "TipoCambioFechaInicialResult").Select(y => new {
                TotalItems = (string)y.Elements().Where(a => a.Name.LocalName == "TotalItems").FirstOrDefault(),
            }).ToList();

            CambioFechaInicial fechas = new CambioFechaInicial(Convert.ToInt32(totalitem.ElementAt(0).TotalItems));

            foreach (var variables in Vars)
            {
                System.Diagnostics.Debug.WriteLine("fecha: " + variables.fecha + " venta " + variables.venta + " compra " + variables.compra);
                fechas.addVar(variables.fecha, Convert.ToDouble(variables.venta), Convert.ToDouble(variables.compra));
            }

            return(fechas);
        }