public async void postXMLData1() { try { string uri = AppStatic.WebServiceBaseURL; // some xml string Uri _url = new Uri(uri, UriKind.RelativeOrAbsolute); xmlUtility listings = new xmlUtility(); getPlaceListRequest _objgetPlaceListRequest = listings.GetUserRequestParameters(); XDocument element = listings.getList(_objgetPlaceListRequest); string file = element.ToString(); var httpClient = new Windows.Web.Http.HttpClient(); var info = AppStatic.WebServiceAuthentication; var token = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(info)); httpClient.DefaultRequestHeaders.Authorization = new Windows.Web.Http.Headers.HttpCredentialsHeaderValue("Basic", token); httpClient.DefaultRequestHeaders.Add("SOAPAction", ""); Windows.Web.Http.HttpRequestMessage httpRequestMessage = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Post, _url); httpRequestMessage.Headers.UserAgent.TryParseAdd("Mozilla/4.0"); IHttpContent content = new HttpStringContent(file, Windows.Storage.Streams.UnicodeEncoding.Utf8); httpRequestMessage.Content = content; Windows.Web.Http.HttpResponseMessage httpResponseMessage = await httpClient.SendRequestAsync(httpRequestMessage); string strXmlReturned = await httpResponseMessage.Content.ReadAsStringAsync(); XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(strXmlReturned); XDocument loadedData = XDocument.Parse(strXmlReturned); var PlaceList = loadedData.Descendants("PlaceList"). Select(x => new PlaceList { PlaceID = x.Element("placeID").Value, PlaceCode = x.Element("placeCode").Value, PlaceName = x.Element("placeName").Value }); } catch (Exception ex) { ExceptionLog obj = new ExceptionLog(); Error objError = new Error(); objError.ErrorEx = ex.Message; obj.CreateLogFile(objError); } }
public async void postXMLData1() { try { string uri = AppStatic.WebServiceBaseURL; // some xml string Uri _url = new Uri(uri, UriKind.RelativeOrAbsolute); xmlUtility listings = new xmlUtility(); getPlaceListRequest _objgetPlaceListRequest = listings.GetUserRequestParameters(); XDocument element = listings.getList(_objgetPlaceListRequest); string file = element.ToString(); var httpClient = new Windows.Web.Http.HttpClient(); var info = AppStatic.WebServiceAuthentication; var token = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(info)); httpClient.DefaultRequestHeaders.Authorization = new Windows.Web.Http.Headers.HttpCredentialsHeaderValue("Basic", token); httpClient.DefaultRequestHeaders.Add("SOAPAction", ""); Windows.Web.Http.HttpRequestMessage httpRequestMessage = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Post, _url); httpRequestMessage.Headers.UserAgent.TryParseAdd("Mozilla/4.0"); IHttpContent content = new HttpStringContent(file, Windows.Storage.Streams.UnicodeEncoding.Utf8); httpRequestMessage.Content = content; Windows.Web.Http.HttpResponseMessage httpResponseMessage = await httpClient.SendRequestAsync(httpRequestMessage); string strXmlReturned = await httpResponseMessage.Content.ReadAsStringAsync(); byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(strXmlReturned); StorageFile files = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("PlaceNames.xml", CreationCollisionOption.ReplaceExisting); String historyTestContent = await FileIO.ReadTextAsync(files); using (var stream = await files.OpenStreamForWriteAsync()) { stream.Write(fileBytes, 0, fileBytes.Length); } LoderPopup.Visibility = Visibility.Collapsed; } catch (Exception ex) { LoderPopup.Visibility = Visibility.Collapsed; ExceptionLog obj = new ExceptionLog(); Error objError = new Error(); objError.ErrorEx = ex.Message; obj.CreateLogFile(objError); } }
public void postXMLData1() { var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { try { string uri = AppStatic.WebServiceBaseURL; // some xml string Uri _url = new Uri(uri, UriKind.RelativeOrAbsolute); xmlUtility listings = new xmlUtility(); getPlaceListRequest _objgetPlaceListRequest = listings.GetUserRequestParameters(); XDocument element = listings.getList(_objgetPlaceListRequest); string file = element.ToString(); var httpClient = new Windows.Web.Http.HttpClient(); var info = AppStatic.WebServiceAuthentication; var token = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(info)); httpClient.DefaultRequestHeaders.Authorization = new Windows.Web.Http.Headers.HttpCredentialsHeaderValue("Basic", token); httpClient.DefaultRequestHeaders.Add("SOAPAction", ""); Windows.Web.Http.HttpRequestMessage httpRequestMessage = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Post, _url); httpRequestMessage.Headers.UserAgent.TryParseAdd("Mozilla/4.0"); IHttpContent content = new HttpStringContent(file, Windows.Storage.Streams.UnicodeEncoding.Utf8); httpRequestMessage.Content = content; Windows.Web.Http.HttpResponseMessage httpResponseMessage = await httpClient.SendRequestAsync(httpRequestMessage); string strXmlReturned = await httpResponseMessage.Content.ReadAsStringAsync(); //StorageFile sampleFile = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("PlaceNames.xml"); //String timestamp = await FileIO.ReadTextAsync(sampleFile); //XDocument loadedData = XDocument.Parse(timestamp); XDocument loadedData = XDocument.Parse(strXmlReturned); var PlaceList = loadedData.Descendants("PlaceList"). Select(x => new PlaceList { PlaceID = x.Element("placeID").Value, PlaceCode = x.Element("placeCode").Value, PlaceName = x.Element("placeName").Value }); foreach (var item in PlaceList) { PlaceList pl = new PlaceList(); pl.PlaceID = item.PlaceID; pl.PlaceName = item.PlaceName; pl.PlaceCode = item.PlaceCode; CityList.Add(pl); } ListMenuItems.ItemsSource = PlaceList; LoderPopup.Visibility = Visibility.Collapsed; } catch (Exception ex) { PopupError.Visibility = Visibility.Visible; LoderPopup.Visibility = Visibility.Collapsed; ExceptionLog obj = new ExceptionLog(); Error objError = new Error(); objError.ErrorEx = ex.Message; obj.CreateLogFile(objError); } }).AsTask(); }