consume a php web service in windows store app


  • hi there,

    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 which i deserialize & store in a variable in WP. but how it would be done in Windows 8 store app.

    what would i use for windows 8 in place of Webclient.

    can you provide sample code for this. I use post method in web service

    please help me on this

    Thursday, March 6, 2014 1:19 PM

All replies

  • You may interested with this: Connecting to web service


    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, March 6, 2014 1:38 PM
  • Thanks for the reply...

    I seen this but not helpful to solve my problem. I don't understand how i deserialize my web service which accept two parameters. 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<RootObject>(e.Result);

    You see that i store all the data in rootObject.

    How these thing can be done in windows 8 app?

    Friday, March 7, 2014 5:45 AM
  • WebClient is replaced by the HttpClient.

    private async Task PostData()
                 Uri uri = new Uri(my web service url);
                 string data = "device_id=" + val + "&quiz_type=all";
                  HttpClient wc = new HttpClient();
                wc.DefaultRequestHeaders["ContentType"] = "application/x-www-form-urlencoded";
                var response = await wc.PostAsync(uri, new HttpStringContent(data)); 
                var str = await response.Content.ReadAsStringAsync();
                    var rootObject = JsonConvert.DeserializeObject<RootObject>(str);

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Friday, March 7, 2014 9:07 AM
  • thanks for the reply.

    How post method is used in this code ?

    Look i have 77 question on service but when i pass device id & quiz type, the no. of question is increased as device id is stored in database via web service. For this, post method is used. how do i get post method on this... so that i get all the questions.....?

    because in debugging mode my device id is not attached with my web service url.

    also tell me why we use Task Keyword for that ?
    • Edited by window11 Friday, March 7, 2014 11:58 AM
    Friday, March 7, 2014 11:34 AM