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.
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
{
}
}
}
}
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 @Subramanyam_B
Have a nice day by Subramanyam Raju :)
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 @Subramanyam_B
Have a nice day by Subramanyam Raju :)
Follow me always at @Subramanyam_B
Have a nice day by Subramanyam Raju :)
Advertisemen
Tidak ada komentar:
Posting Komentar