Travelport / travelport-uapi-tutorial-c-sharp

The travelport-uapi-tutorial-c-sharp is a C# project for Universal API that will help you connect and code a standard Air availablity call and Hotel search, details, and booking flow.
35 stars 30 forks source link

Error in Getting List of AirPorts ASP Core #216

Closed YousifALF closed 3 years ago

YousifALF commented 3 years ago

Hello , we are using ASP Core 3.1 to develop a web application, we have added all the needed WSDL files and fallow all the instructions. I am just trying to get the list of the AirPorts at first (then will search & book the ticket ) but we are getting errors.
error that we are getting for now is "cannot convert from 'UtilService.ReferenceDataRetrieveReq' to 'UtilService.serviceRequest13" please check my code below

   ReferenceDataRetrieveReq retrieveReq = new ReferenceDataRetrieveReq();
        ReferenceDataRetrieveRsp retrieveRsp;
     //System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        retrieveReq.BillingPointOfSaleInfo = new BillingPointOfSaleInfo()
        {
            OriginApplication = "UAPI"
        };

        retrieveReq.TargetBranch = "xxxx";//targetBranch
        retrieveReq.TypeCode = "CityAirport";

        retrieveReq.ReferenceDataSearchModifiers = new ReferenceDataSearchModifiers()
        {
            MaxResults = "20000",
            StartFromResult = "0",
            ProviderCode = "1G"
        };

        //UTL: https://emea.universal-api.pp.travelport.com/B2BGateway/connect/uAPI/UtilService
        BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
        EndpointAddress endpointAddress = new EndpointAddress(myOptions.Value.EndpointUrl);
        ReferenceDataRetrievePortTypeClient client = new ReferenceDataRetrievePortTypeClient
                            (basicHttpBinding, endpointAddress);

        client.ClientCredentials.UserName.UserName = "xxx";
        client.ClientCredentials.UserName.Password = "xxx";
        try
        {
            var httpHeaders = Helper.ReturnHttpHeader();
            client.Endpoint.EndpointBehaviors.Add(new HttpHeadersEndpointBehavior(httpHeaders));
            **retrieveRsp = await client.serviceAsync(retrieveReq);//Error Here**

            if (retrieveRsp != null)
            {
                IEnumerator dataItems = retrieveRsp.ReferenceDataItem.GetEnumerator();
                int count = 0;
                while (dataItems.MoveNext() && count < 50)//We have added 50 Airports in the List, You can add all if you want, Just remove the count
                {
                    ReferenceDataItem item = (ReferenceDataItem)dataItems.Current;
                    airportsList.Add(item.Code, item.Name);
                    count++;
                }

            }
        }
        catch (Exception se)
        {
            Console.WriteLine("Error : " + se.Message);
            client.Abort();
            return null;
        }

` image

FYI: Same code from the Sample project,and the sample project we are able to get the airports code list

salmanelahi93 commented 3 years ago

Hi YousifALF,

Please try with synchronous request.

retrieveRsp = client.service(retrieveReq);

Synchronous req working perfectly.

YousifALF commented 3 years ago

Hello @salmanelahi93 . Thanks, I have updated my Code and got all the AirPorts List