i made an app in windows phone successfully & now i want to make it for windows 8 store app but i stuck on a point where i want to my web service in store app.
I use webclient in WP but i don't know anything about how to access web service in Windows 8 store app. My web service return data in json format i deserialize & store in a variable in WP & i use post method . but how it would be done in Windows 8 store app. what would i use for windows 8 in place of Webclient.
i post my windows phone code
private void PostData() { Uri uri = new Uri(my web service url); string data = "device_id=" + val + "&quiz_type=all"; WebClient wc = new WebClient(); wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; wc.UploadStringAsync(uri, data); wc.UploadStringCompleted += wc_UploadComplete; } public void wc_UploadComplete(object sender, UploadStringCompletedEventArgs e) { var rootObject = JsonConvert.DeserializeObject(e.Result); }You see that i store all the data in rootObject. How these thing can be done in windows 8 app?
Ramprasath R KPosted Apr 30, 2014, 4:21 AM
var client = new HttpClient();
string data = "device_id=" + val + "&quiz_type=all";
var postContent = new StringContent(data, Encoding.UTF8, "application/x-www-form-urlencoded");
// send request asynchronously and continue when complete
var response = await client.PostAsync(address, postContent);
// check that response was successful or throw exception response.EnsureSuccessStatusCode();
//Read the JSON response
var content = await response.Content.ReadAsStringAsync();