Remark : uAPI Soap Call and Parsing sample C#
Main
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
using System; using System.Collections.Generic; using System.IO; using System.Xml; namespace uAPICoreConsole { class Program { static void Main(string[] args) { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls12; string EndPoint = "https://apac.universal-api.pp.travelport.com/B2BGateway/connect/uAPI/AirService"; string credentials = "*******************"; string Password = "*******j"; string SoapRequest = @"<soapenv:Envelope xmlns:soapenv = 'http://schemas.xmlsoap.org/soap/envelope/'" + " xmlns:air='http://www.travelport.com/schema/air_v50_0' " + " xmlns:com='http://www.travelport.com/schema/common_v50_0'>" + " <soapenv:Body>" + " <air:LowFareSearchReq TraceId='2021122918322322' TargetBranch='P*******' SolutionResult='true' AuthorizedBy='user' >" + " <com:BillingPointOfSaleInfo OriginApplication='UAPI'/>" + " <air:SearchAirLeg>" + " <air:SearchOrigin>" + " <com:CityOrAirport Code='DEL'/>" + " </air:SearchOrigin>" + " <air:SearchDestination>" + " <com:CityOrAirport Code='BOM'/>" + " </air:SearchDestination>" + " <air:SearchDepTime PreferredTime='2022-05-12'> </air:SearchDepTime>" + " </air:SearchAirLeg>" + " <air:AirSearchModifiers>" + " <air:PreferredProviders>" + " <com:Provider Code='1G' />" + " </air:PreferredProviders>" + " <air:PermittedCarriers>" + " <com:Carrier Code='AI' />" + " </air:PermittedCarriers>" + " <air:PreferredCabins>" + " <com:CabinClass Type='Economy' />" + " </air:PreferredCabins>" + " <air:FlightType NonStopDirects='true' StopDirects='true' SingleOnlineCon='true' DoubleOnlineCon='false' TripleOnlineCon='false' SingleInterlineCon='false' DoubleInterlineCon='false' TripleInterlineCon='false' />" + " </air:AirSearchModifiers>" + " <com:SearchPassenger Code='ADT'/>" + " <air:AirPricingModifiers ETicketability='Required' FaresIndicator='AllFares'/>" + " </air:LowFareSearchReq>" + " </soapenv:Body>" + "</soapenv:Envelope>"; string Res = string.Empty; try { SoapClass SC = new SoapClass(); Res = SC.CallWebService(1, EndPoint, SoapRequest, credentials, Password); SC = null; } catch (Exception ex) { Res = ex.Message.ToString(); Res = "<ERR>" + Res + "</ERR>"; } //Console.WriteLine(Res); XmlDocument doc = new XmlDocument(); XmlNodeList nodeList; doc.LoadXml(Res); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("common_v50_0", "http://www.travelport.com/schema/common_v50_0"); nsmgr.AddNamespace("air", "http://www.travelport.com/schema/air_v50_0"); XmlNode root = doc.DocumentElement; nodeList = doc.SelectNodes("//air:AirPricingSolution", nsmgr); if (nodeList.Count > 0) { foreach (XmlNode DATA in nodeList) { Console.WriteLine("key: {0}", DATA.Attributes["Key"].Value); Console.WriteLine("ApproximateTotalPrice: {0}", DATA.Attributes["ApproximateTotalPrice"].Value); Console.WriteLine("PlatingCarrier: {0}", DATA.SelectSingleNode("air:AirPricingInfo", nsmgr).Attributes["PlatingCarrier"].Value); } } Console.ReadLine(); } } |
SoapClass
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
using System; using System.Text; using System.Xml; using System.Net; using System.IO; namespace uAPICoreConsole { class SoapClass { public string CallWebService(int ServerType, string EndPoint, string SoapData, string credentials, string Password) { var _action = EndPoint; XmlDocument soapEnvelopeXml = CreateSoapEnvelope(SoapData); HttpWebRequest webRequest = CreateWebRequest(ServerType, _action, credentials, Password); InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest); // begin async call to web request. IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null); // suspend this thread until call is complete. You might want to // do something usefull here like update your UI. asyncResult.AsyncWaitHandle.WaitOne(); //주석처리 // get the response from the completed web request. string soapResult; using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult)) { using (StreamReader rd = new StreamReader(webResponse.GetResponseStream())) { soapResult = rd.ReadToEnd(); } } return soapResult; } private HttpWebRequest CreateWebRequest(int ServerType, string action, string credentials, string Password) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(action); //action 사용 //webRequest.Headers.Add("SOAPAction", action); //아래아 같이 수정 webRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials + ":" + Password))); webRequest.ContentType = "text/xml;charset=\"utf-8\""; webRequest.Accept = "text/xml"; webRequest.Method = "POST"; return webRequest; } private XmlDocument CreateSoapEnvelope(string SoapData) { XmlDocument soapEnvelop = new XmlDocument(); soapEnvelop.LoadXml(SoapData); return soapEnvelop; } private void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest) { using (Stream stream = webRequest.GetRequestStream()) { soapEnvelopeXml.Save(stream); } } } } |
Console.Writeline
Vim
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
key: zmZ1Y++pWDKAQtfLBAAAAA== ApproximateTotalPrice: KRW46600 PlatingCarrier: AI key: zmZ1Y++pWDKAntfLBAAAAA== ApproximateTotalPrice: KRW46600 PlatingCarrier: AI key: zmZ1Y++pWDKAxtfLBAAAAA== ApproximateTotalPrice: KRW46600 PlatingCarrier: AI key: zmZ1Y++pWDKA7tfLBAAAAA== ApproximateTotalPrice: KRW46600 PlatingCarrier: AI key: zmZ1Y++pWDKAFufLBAAAAA== ApproximateTotalPrice: KRW46600 PlatingCarrier: AI key: zmZ1Y++pWDKAPufLBAAAAA== ApproximateTotalPrice: KRW46600 PlatingCarrier: AI key: zmZ1Y++pWDKAaufLBAAAAA== ApproximateTotalPrice: KRW46600 PlatingCarrier: AI key: zmZ1Y++pWDKAbufLBAAAAA== ApproximateTotalPrice: KRW71200 PlatingCarrier: AI key: zmZ1Y++pWDKA6ufLBAAAAA== ApproximateTotalPrice: KRW72600 PlatingCarrier: AI key: zmZ1Y++pWDKAYvfLBAAAAA== ApproximateTotalPrice: KRW72600 PlatingCarrier: AI key: zmZ1Y++pWDKAZvfLBAAAAA== ApproximateTotalPrice: KRW74100 PlatingCarrier: AI key: zmZ1Y++pWDKArvfLBAAAAA== ApproximateTotalPrice: KRW80200 PlatingCarrier: AI key: zmZ1Y++pWDKA9vfLBAAAAA== ApproximateTotalPrice: KRW81400 PlatingCarrier: AI key: zmZ1Y++pWDKA+vfLBAAAAA== ApproximateTotalPrice: KRW91300 PlatingCarrier: AI key: zmZ1Y++pWDKAQwfLBAAAAA== ApproximateTotalPrice: KRW91500 PlatingCarrier: AI key: zmZ1Y++pWDKAuwfLBAAAAA== ApproximateTotalPrice: KRW91500 PlatingCarrier: AI key: zmZ1Y++pWDKA5wfLBAAAAA== ApproximateTotalPrice: KRW91500 PlatingCarrier: AI key: zmZ1Y++pWDKA6wfLBAAAAA== ApproximateTotalPrice: KRW95200 PlatingCarrier: AI key: zmZ1Y++pWDKAYxfLBAAAAA== ApproximateTotalPrice: KRW96500 PlatingCarrier: AI key: zmZ1Y++pWDKAqxfLBAAAAA== ApproximateTotalPrice: KRW101000 PlatingCarrier: AI key: zmZ1Y++pWDKArxfLBAAAAA== ApproximateTotalPrice: KRW107400 PlatingCarrier: AI key: zmZ1Y++pWDKAHyfLBAAAAA== ApproximateTotalPrice: KRW107400 PlatingCarrier: AI key: zmZ1Y++pWDKAIyfLBAAAAA== ApproximateTotalPrice: KRW120300 PlatingCarrier: AI |