public static SearchParameterVO GetByCustomerNumber(string customerNo) { List <CustomerModel> objCustName = new List <CustomerModel>(); ServiceResponceModel lstServiceResult = new ServiceResponceModel(); List <ServiceModel> lstService = new List <ServiceModel>(); SearchParameterVO objSearch = new SearchParameterVO(); List <LstSearchParamVO> objSerchParam = new List <LstSearchParamVO>(); objSerchParam = new List <LstSearchParamVO> { new LstSearchParamVO { ColumnName = "Customer.cust_no_717", Name = "Customer NUmber", Condition = "Equals", ValueOne = customerNo, ValueTwo = null } }; objSearch.UserLanguageCulture = "en-US"; objSearch.SSOID = "503106097"; objSearch.VATAccess = false.ToString(); objSearch.lstSearchParamVO = objSerchParam; return(objSearch); }
public static async Task <string> GetServiceResponse() { SearchParameterVO objSearch = new SearchParameterVO(); List <lstSearchParamVO> objSerchParam = new List <lstSearchParamVO>(); objSerchParam = new List <lstSearchParamVO> { new lstSearchParamVO { ColumnName = "Customer.cust_no_717", Name = "Customer Number", Condition = "Equals", ValueOne = "0001610280", ValueTwo = null } }; objSearch.UserLanguageCulture = "en-US"; objSearch.SSOID = "503106097"; objSearch.VATAccess = false.ToString(); objSearch.LstSearchParam = objSerchParam; HttpResponseMessage responses = null; string str = string.Empty; HttpClient httpClient = new HttpClient(); httpClient.BaseAddress = new Uri("http://localhost:55769/API"); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); string userName = "******"; string pass = "******"; string UserViewLanguage = "en-US"; string CustomerNo = "0001610280"; var base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{userName}:{pass}")); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64String); httpClient.Timeout = TimeSpan.FromMinutes(5); //for (int i = 0; i < 5; i++) //{ //http://localhost:55769/API/Collection/api/Search/Filter/Customer/12/503106097 try { var response = httpClient.GetStringAsync(" http://localhost:55769/API/Collection/api/Search/Filter/Customer/12/503106097"); response.Wait(TimeSpan.FromMinutes(3)); var results = response.Result; //if (i == 5) //{ return(results.ToString()); //} //i += 1; Thread.Sleep(10000); } catch (Exception e) { return(e.Message.ToString()); } //} /* try * { * * var client = new HttpClient(); * client.BaseAddress = new Uri("http://localhost:55769/API"); * client.DefaultRequestHeaders.Accept.Clear(); * client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); * * var content = new StringContent(JsonConvert.SerializeObject(objSearch), Encoding.UTF8, "application/json"); * * using (var response = await client.PostAsync("/Collection/Search/Filter/Customer/", content)) * { * Thread.Sleep(10000); * if (response.IsSuccessStatusCode) * { * var resp = await response.Content.ReadAsStringAsync(); * // Get the URI of the created resource. * Uri returnUrl = response.Headers.Location; * Console.WriteLine(returnUrl); * return JObject.Parse(resp); * } * else * return null; * } * * //HttpResponseMessage responses = await client.PostAsync("/Collection/Search/Filter/Customer/", content); * //if (response.IsSuccessStatusCode) * //{ * // var resp = await response.Content.ReadAsStringAsync(); * // return JObject.Parse(resp); * //} * //else * // return null; * * } * catch (Exception ex) * { * return null; * } */ return(string.Empty); }
public static async Task <List <CustomerModel> > GetServiceResponse(string CustomerNo, string customerName) { List <CustomerModel> objCustDetails = new List <CustomerModel>(); SearchParameterVO objSearch = null; if (CustomerNo == null) { objSearch = new SearchParameterVO(); objSearch = CommonClasses.GetByCustomerNumber(CustomerNo); } else { objSearch = new SearchParameterVO(); objSearch = CommonClasses.GetByCustomerName(customerName); } HttpResponseMessage responses = null; HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //var base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{userName}:{pass}")); //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64String); //httpClient.Timeout = TimeSpan.FromMinutes(5); //for (int i = 0; i < 5; i++) //{ // string message = string.Empty; //http://localhost:55769/API/Collection/api/Search/Filter/Customer/12/503106097 try { var content = new StringContent(JsonConvert.SerializeObject(objSearch), Encoding.UTF8, "application/json"); FakeService fakeService = new FakeService(); List <ServiceModel> data = await fakeService.GetFakeData(CustomerNo); for (int i = 0; i < data.Count; i++) { objCustDetails = new List <CustomerModel> { new CustomerModel { CustomerName = data[i].Name, CustomerNumber = data[i].CustomerNo, Balance = data[i].Balance } }; //balance = resultData.data.aaData[i].Balance; //no = resultData.data.aaData[i].CustomerNo; //name = resultData.data.aaData[i].Name; } return(objCustDetails); //// responses = await httpClient.PostAsync("http://localhost:55769/API/Collection/api/Search/Customer", content); //if (responses.IsSuccessStatusCode) //{ // objCustDetails = new List<CustomerModel>(); // var resp = await responses.Content.ReadAsStringAsync(); // var resultData = JsonConvert.DeserializeObject<MainModel>(resp.ToString()); // //string balance = string.Empty; // //string no = string.Empty; // //string name = string.Empty; // for (int i = 0; i < resultData.data.aaData.Count; i++) // { // objCustDetails = new List<CustomerModel> { new CustomerModel // { CustomerName = resultData.data.aaData[i].Name , // CustomerNumber = resultData.data.aaData[i].CustomerNo, // Balance = resultData.data.aaData[i].Balance // } }; // //balance = resultData.data.aaData[i].Balance; // //no = resultData.data.aaData[i].CustomerNo; // //name = resultData.data.aaData[i].Name; // } // // message ="Customer Name :"+ name+" Customer No :" + no+" Balance :"+balance; // return objCustDetails.ToString(); //message; //} //else //{ // return objCustDetails.ToString(); //} } catch (Exception e) { return(objCustDetails); } }