Esempio n. 1
0
        public async Task <UkprnLookupResponse> GetTrainingProviderByUkprn(long ukprn)
        {
            // Due to a bug in .net core, we have to parse the SOAP XML from UKRLP by hand
            // If this ever gets fixed then look to remove this code and replace with 'Add connected service'
            // https://github.com/dotnet/wcf/issues/3228

            var request = _serializer.BuildUkrlpSoapRequest(ukprn, _config.UkrlpApiAuthentication.StakeholderId,
                                                            _config.UkrlpApiAuthentication.QueryId);

            var requestMessage =
                new HttpRequestMessage(HttpMethod.Post, _config.UkrlpApiAuthentication.ApiBaseAddress)
            {
                Content = new StringContent(request, Encoding.UTF8, "text/xml")
            };

            var responseMessage = await _httpClient.SendAsync(requestMessage);

            if (!responseMessage.IsSuccessStatusCode)
            {
                var failureResponse = new UkprnLookupResponse
                {
                    Success = false,
                    Results = new List <ProviderDetails>()
                };
                return(await Task.FromResult(failureResponse));
            }

            string soapXml = await responseMessage.Content.ReadAsStringAsync();

            var matchingProviderRecords = _serializer.DeserialiseMatchingProviderRecordsResponse(soapXml);

            ProviderDetails providerDetails = null;

            if (matchingProviderRecords != null)
            {
                providerDetails = Mapper.Map <ProviderDetails>(matchingProviderRecords);

                var result = new List <ProviderDetails>
                {
                    providerDetails
                };
                var resultsFound = new UkprnLookupResponse
                {
                    Success = true,
                    Results = result
                };
                return(await Task.FromResult(resultsFound));
            }
            else
            {
                var noResultsFound = new UkprnLookupResponse
                {
                    Success = true,
                    Results = new List <ProviderDetails>()
                };
                return(await Task.FromResult(noResultsFound));
            }
        }
Esempio n. 2
0
        private async Task <UkprnLookupResponse> GetUkprnLookupResponse(string request)
        {
            var requestMessage =
                new HttpRequestMessage(HttpMethod.Post, _config.UkrlpApiAuthentication.ApiBaseAddress)
            {
                Content = new StringContent(request, Encoding.UTF8, "text/xml")
            };

            var responseMessage = await _httpClient.SendAsync(requestMessage);

            if (!responseMessage.IsSuccessStatusCode)
            {
                var failureResponse = new UkprnLookupResponse
                {
                    Success = false,
                    Results = new List <ProviderDetails>()
                };
                return(await Task.FromResult(failureResponse));
            }

            var soapXml = await responseMessage.Content.ReadAsStringAsync();

            var matchingProviderRecords = _serializer.DeserialiseMatchingProviderRecordsResponse(soapXml);

            if (matchingProviderRecords != null)
            {
                var result = matchingProviderRecords.Select(Mapper.Map <ProviderDetails>).ToList();

                var resultsFound = new UkprnLookupResponse
                {
                    Success = true,
                    Results = result
                };
                return(await Task.FromResult(resultsFound));
            }
            else
            {
                var noResultsFound = new UkprnLookupResponse
                {
                    Success = true,
                    Results = new List <ProviderDetails>()
                };
                return(await Task.FromResult(noResultsFound));
            }
        }