private static void TaskAsincrono(object data) { RichiestaVerifica item = (RichiestaVerifica)data; try { PreventWebServices.WebReferencePrevent.WSPreventService wsp = new PreventWebServices.WebReferencePrevent.WSPreventService(); item.XmlRisposta = wsp.book("WinTicket", WsConfig.Username, WsConfig.Password, "V", item.XmlRichiesta); //item.XmlRisposta = wsp.book("WinTicket", "Luca", "3292285430", "V", item.XmlRichiesta); item.DataRisposta = DateTime.Now; Console.WriteLine(item.XmlRichiesta); Console.WriteLine(item.XmlRisposta); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(item.XmlRisposta)); XmlSerializer xml = new XmlSerializer(typeof(prevent.verifica.Out)); prevent.verifica.Out risposta = (prevent.verifica.Out)xml.Deserialize(stream); item.CodiceErrore = risposta.DescrizioneErrore; if (risposta.ReturnCode == "00") { item.Disponibile = true; } else { item.Disponibile = false; } } catch (Exception ex) { item.CodiceErrore = ex.Message; item.XmlRisposta = string.Empty; item.DataRisposta = DateTime.Now; item.Disponibile = false; } lock (SyncRoot) { Elenco.Add(item); } }
public static prevent.get.Out MakeGet() { UltimoErrore = null; PreventWebServices.WebReferencePrevent.WSPreventService wsp = new PreventWebServices.WebReferencePrevent.WSPreventService(); string risposta = string.Empty; try { Console.WriteLine("WS_URL: " + wsp.Url); risposta = wsp.book("WinTicket", WsConfig.Username, WsConfig.Password, "G", string.Empty); } catch (Exception ex) { UltimoErrore = new prevent.verifica.Out(); UltimoErrore.DescrizioneErrore = string.Format("Risposta non corretta dal servizio remoto: {0}: {1}", ex.Source, ex.Message); UltimoErrore.ReturnCode = "998"; risposta = string.Empty; } if (!string.IsNullOrEmpty(risposta)) { Console.WriteLine(risposta); risposta = risposta.Replace("+01:00", string.Empty); risposta = risposta.Replace("+02:00", string.Empty); try { if (!risposta.Contains("ReturnCode")) { MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(risposta)); XmlSerializer xml = new XmlSerializer(typeof(prevent.get.Out)); prevent.get.Out dati = (prevent.get.Out)xml.Deserialize(stream); dati.MostraTipo = "0"; var mostra = new int[] { 277, 278, 279 }; foreach (var num in mostra) { if (risposta.Contains(string.Format("<IdTipoBiglietto>{0}</IdTipoBiglietto>", num))) { dati.MostraTipo = "1"; } } return(dati); } else { // errore MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(risposta)); XmlSerializer xml = new XmlSerializer(typeof(prevent.verifica.Out)); UltimoErrore = (prevent.verifica.Out)xml.Deserialize(stream); } } catch (Exception ex) { UltimoErrore = new prevent.verifica.Out(); UltimoErrore.DescrizioneErrore = String.Format("Risposta non corretta dal servizio remoto: {0} ({1})", (risposta.Length < 200 ? risposta : string.Empty), ex.Message); UltimoErrore.ReturnCode = "999"; } } return(null); }
public static bool Prenota(prevent.prenotazione.Parametri parametri, prevent.get.Out vecchiaprenotazione) { UltimoErrore = null; PreventWebServices.WebReferencePrevent.WSPreventService wsp = new PreventWebServices.WebReferencePrevent.WSPreventService(); string richiesta = GetXmlRichiesta(parametri); if (vecchiaprenotazione != null) { richiesta = GetXmlRichiesta(CreaUpdate(parametri, vecchiaprenotazione)); } string risposta = string.Empty; try { if (vecchiaprenotazione != null) { risposta = wsp.book("WinTicket", WsConfig.Username, WsConfig.Password, "U", richiesta); } else { risposta = wsp.book("WinTicket", WsConfig.Username, WsConfig.Password, "P", richiesta); } } catch (Exception) { risposta = string.Empty; } Console.WriteLine(richiesta); Console.WriteLine(risposta); parametri.CodiceTransWinTicket = string.Empty; if (risposta.Contains(@"ReturnCode=""00""")) { if (vecchiaprenotazione != null) { parametri.CodiceTransWinTicket = vecchiaprenotazione.NumeroPrenotazione; } else { int len1 = @"<NumeroPrenotazione>".Length; int pos1 = risposta.IndexOf(@"<NumeroPrenotazione>"); int pos2 = risposta.IndexOf(@"</NumeroPrenotazione>"); parametri.CodiceTransWinTicket = risposta.Substring(pos1 + len1, pos2 - pos1 - len1); Console.WriteLine(String.Format("PRENOTAZIONE:[{0}]", parametri.CodiceTransWinTicket)); } return(true); } else { if (!string.IsNullOrEmpty(risposta)) { // errore MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(risposta)); XmlSerializer xml = new XmlSerializer(typeof(prevent.verifica.Out)); UltimoErrore = (prevent.verifica.Out)xml.Deserialize(stream); } return(false); } }