private string CreateXmlStringFromObject(AirShoppingRQ airShopping) { var soap = new SoapEnvelope() { body = new ResponseBody <AirShoppingRQ> { AirShoppingRQ = airShopping } }; XmlSerializer serializer = new XmlSerializer(typeof(SoapEnvelope)); var settings = new XmlWriterSettings(); settings.Indent = true; settings.OmitXmlDeclaration = true; using (var stream = new StringWriter()) using (var writer = XmlWriter.Create(stream, settings)) { serializer.Serialize(writer, soap); return(stream.ToString()); } //var writer = new StringWriter(); //serializer.Serialize(writer, soap); //return writer.ToString(); }
public string CreateXml(FlightSearch search) { var airShoppingRQ = new AirShoppingRQ(); airShoppingRQ.Document = _documentFactory.Create(); airShoppingRQ.Party = _partyBuilder.Create(); airShoppingRQ.Travelers = _travelerBuilder.Create(search); airShoppingRQ.CoreQuery = _coreQueryBuilder.Create(search); airShoppingRQ.Preference = _preferenceBuilder.Create(search); var soap = new SoapEnvelope() { body = new ResponseBody <AirShoppingRQ> { AirShoppingRQ = airShoppingRQ } }; return(_xmlService.CreateXmlStringFromObject <SoapEnvelope>(soap)); }
/// <summary> /// The invoke. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="ServiceListRS"/>. /// </returns> /// <exception cref="Exception"> /// </exception> public AirShoppingRS Invoke(AirShoppingRQ request) { try { var reqXml = CreateFmsSvcSoapHeaderAndBodyRequest(request).Replace("\"", "'").Replace(@"xmlns='http://farelogix.com/flx/AirShoppingRQ'", string.Empty); var req = CreateWebRequest(@"https://stg.farelogix.com/xmlts/sandboxdm-wsdl"); req.AutomaticDecompression = DecompressionMethods.GZip; using (var strWri = new StreamWriter(req.GetRequestStream())) { strWri.WriteLine(reqXml); strWri.Close(); } var st = new Stopwatch(); st.Start(); using (var response = req.GetResponse() as HttpWebResponse) { st.Stop(); var elapsedMilliseconds = st.ElapsedMilliseconds; if (response != null) { using (var strRead = new StreamReader(response.GetResponseStream())) { //var xDoc = XDocument.Load(strRead); XmlDocument xDoc = new XmlDocument(); xDoc.Load(strRead); var responseContent = Read(xDoc);// xDoc.Descendants("FlxTransactionResponse").First().FirstNode.ToString(); AirShoppingRS flxFmsResponse; responseContent = responseContent.Replace("\"", "'").Replace(@"xmlns='http://farelogix.com/flx/AirShoppingRS'", string.Empty); using (var reader = new StringReader(responseContent))// new StreamReader(stream)) { var ss = reader.ReadToEnd(); } using (var reader = new StringReader(responseContent))// new StreamReader(stream)) { flxFmsResponse = (AirShoppingRS)deserializer.Deserialize(reader); } return flxFmsResponse; } } else { throw new Exception("No response reveived"); } } } catch (WebException wex) { var failureReason = string.Empty; using (var httpResponse = wex.Response as HttpWebResponse) { if (httpResponse != null) { using (var responseStream = httpResponse.GetResponseStream()) { if (responseStream != null) { using (var reader = new StreamReader(responseStream)) { failureReason = reader.ReadToEnd(); } } } } } throw; } catch (Exception ex) { throw; } return null; }