public static CambioDia InvokeServiceCambioDia() { CambioDia resultado; //Calling CreateSOAPWebRequest method HttpWebRequest request = CreateSOAPWebRequestCambioDia(); 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> <TipoCambioDia xmlns=""http://www.banguat.gob.gt/variables/ws/"" /> </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; } } XDocument doc = XDocument.Parse(xml); var VarDolar = doc.Descendants().Where(x => x.Name.LocalName == "VarDolar").Select(y => new { fecha = (string)y.Elements().Where(z => z.Name.LocalName == "fecha").FirstOrDefault(), cambio = (string)y.Elements().Where(z => z.Name.LocalName == "referencia").FirstOrDefault() }).ToList(); System.Diagnostics.Debug.WriteLine(xml); resultado = new CambioDia(VarDolar.ElementAt(0).fecha, Convert.ToDouble(VarDolar.ElementAt(0).cambio)); System.Diagnostics.Debug.WriteLine(VarDolar.ElementAt(0).fecha); System.Diagnostics.Debug.WriteLine(VarDolar.ElementAt(0).cambio); return(resultado); }
public void TestCambioDia() { CambioDia fechareal = new CambioDia("", -7.0); if (string.IsNullOrEmpty(fechareal.Dia)) { Assert.Pass(); } if (double.IsNegative(fechareal.Cambio)) { Assert.Pass(); } CambioDia fechafake = new CambioDia("19/03/1996", 7.0); if (string.IsNullOrEmpty(fechafake.Dia)) { Assert.Fail(); } if (double.IsNegative(fechafake.Cambio)) { Assert.Fail(); } try { CambioDia pordia = Practica3_4.TipoCambioService.InvokeServiceCambioDia(); if (pordia.Dia.Equals(DateTime.Today.ToString("dd/MM/yyyy"))) { Assert.Pass(); } else { Assert.Fail(); } } catch (Exception) { Assert.Fail(); } }
protected void Button1_Click(object sender, EventArgs e) { CambioDia cambiodia = TipoCambioService.InvokeServiceCambioDia(); response.Text = cambiodia.Dia + "---" + cambiodia.Cambio; }