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

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

Advertisemen

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  :)

Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D