I tried a lot and searched a lot to find out a method to return an XML to the silverlight application and wasted almost 3 hours on it . Then I found a way to solve the problem.The code for it is shown below.
It catches security errors if the distant URL needs a session variable to access the file.
If it doesnt need a session variable and data is of the correct format, it works properly.
private void RequestContent()
{
Uri address = new Uri(uri);
//You can supply this URI from a text box or hard code it.
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new
DownloadStringCompletedEventHandler
(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(address);
}
void webClient_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
MessageBox.Show(e.Result);
txtBlock.Text = e.Result.ToString();
}
else
{
MessageBox.Show(e.Error.ToString());
txtBlock.Text = e.Error.ToString();
}
}
See you alll.......
It catches security errors if the distant URL needs a session variable to access the file.
If it doesnt need a session variable and data is of the correct format, it works properly.
private void RequestContent()
{
Uri address = new Uri(uri);
//You can supply this URI from a text box or hard code it.
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new
DownloadStringCompletedEventHandler
(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(address);
}
void webClient_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
MessageBox.Show(e.Result);
txtBlock.Text = e.Result.ToString();
}
else
{
MessageBox.Show(e.Error.ToString());
txtBlock.Text = e.Error.ToString();
}
}
See you alll.......
No comments:
Post a Comment