Google WindowsPhone 8.0 vs WindowsPhone 8.1:Now HttpClient is alternative for WebCleint(C#-XAML) | SubramanyamRaju Xamarin & Windows App Dev Tutorials

Friday 4 July 2014

WindowsPhone 8.0 vs WindowsPhone 8.1:Now HttpClient is alternative for WebCleint(C#-XAML)

Introduction:

Previously in windowsphone 8.0 ,to request webservcie we are using "WebClient " class which is available from "System.Net" namespace.And now "Webclient" is no longer available for windowsphone store 8.1.So what is alternative for "WebClient" is "HttpClient" class which is avaialable from "Windows.Web.Http or System.Net.Http" name space's.
Note:HttpWebRequest is still available for both windowsphone store 8.1 & silverlight windowsphone

Description:

Ok lets start to comaprisions between 'WebClient' and 'HttpClient ' .

WindowsPhone 8.0:

In wp8.0  we are using WebClient instance and then uses it to download data from a server(i.e WebService).So lets remember it now

C#

void GetServiceData()  
        {  
            WebClient webclient = new WebClient();  
            Uri uristring = null;  
           //Please replace your webservice url here        
            uristring = new Uri("http://example.com/datalist.aspx");                                       webclient.Headers["ContentType"] = "application/json";  
            webclient.DownloadStringCompleted += wc_DownloadloadStringCompleted;  
            webclient.DownloadStringAsync(uristring,"");  
        }  
        private void wc_DownloadloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)  
        {  
            try  
            {  
                  
                if (e.Result != null)  
                {  
                    string ResponseResult = e.Result.ToString();  
                    //To Do Your functionality  
                }  
            }  
            catch  
            {  
            }  
        }

WindowsPhone 8.1:

As we earlier discussion from "Introduction" section,now "WebClient" class is no longer available for windows phone store 8.1 .But it is still available in silverlight windowsphone 8.1.

So now we are going to use "HttpClient" to request data from server(i.e WebService)
C#

void GetServiceData()  
        {  
            HttpClient client = new HttpClient(); 
            string ResponceResult= await client.GetStringAsync(new Uri("http://example.com/datalist.aspx"));  

Note: Please share your thoughts,what you think about this post,Is this post really helpful for you?otherwise it would be very happy ,if you have any thoughts for to implement this requirement in any another way?I always welcome if you drop comments on this post and it would be impressive.

Follow me always at  
Have a nice day by  :)

7 comments:

  1. Post was helpful... I think httpclient is easier compared to webclient... It will be nice if you evaluate them and tell us the pros and cons of both.

    ReplyDelete
  2. Hi I have a doubt with Windows phone 8.1 development. Am developing An app which continuously tracks users location using bing maps. Is it not possible using Windows phone 8.1 runtime? Your answers will be very helpful. If so pls guide me with any code material to help me proceed further.

    ReplyDelete
  3. @avinash arun

    If you didn't get an answer yet. See http://msdn.microsoft.com/en-us/library/windows/apps/jj247548(v=vs.105).aspx
    "Applies to: Windows Phone 8 and Windows Phone Silverlight 8.1 only"

    I remember this Channel 9 video say near the end in Phone 8.1 apps only silverlight or phone 8 can continuously track location.

    http://channel9.msdn.com/Series/Building-Apps-for-Windows-Phone-8-1/01

    ReplyDelete
  4. hello!
    i'm a beginner of WP8.
    i read the code above and i think the code just download the webservice to the phone memory, not the isolated storage.
    how to save the webservice to the storage ?

    ReplyDelete
  5. Hey! Can you help me with post request? I would like to send an email id of someone to the server. How could I do that? I searched the net and there isnt any example for PostAsync request for httpclient under System.Web.Http. Can you please help me??

    ReplyDelete
  6. I want to concurrent request using HttpClient. how is possible?

    ReplyDelete
  7. Hi Subbu,
    Could you please tell me that how can we use SSL certificate in WP 8.1 or how to get response in HTTPS? I have read lots of blogs but did not get any fruitful result to implement HTTPS in WP 8.1.
    Please do revert as soon as possible.

    Thanks,
    Nishant

    ReplyDelete

Search Engine Submission - AddMe