Not able to connect to webservice from a WP7 emulator
private void button2_Click(object sender, RoutedEventArgs e)
{
WebClient wb = new WebClient();
wb.DownloadStringCompleted += new Dow开发者_如何学JAVAnloadStringCompletedEventHandler(wb_DownloadStringCompleted);
wb.DownloadStringAsync(new Uri("http://weather.yahooapis.com/forecastrss?w=2502265"));
}
void wb_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
XElement xmlResult = XElement.Parse(e.Result);
}
This is code i have used. I am getting an error "Unable to connect to the remote server". I am able to connect to internet from the IE browser in the emulator.
Suggest a suitable solution.
Did you try to restart your emulator ? Because it happens to me : I got this error with the emulator but none with a simple console programm. After a restart of VS, it works.
I cannot reproduce your problem with the code you have provided. Are you sure you're not stuck behind a firewall or something that blocks your request? Try using Fiddler (or a product like it) to see whats going on.
To allow the Emulator in friewall.
- Open Control Panel\System and Security\Windows Firewall\Allowed Programs
- Click on "Change Settings" to enable "Allow another program"
- Browse - > "C:\Program Files (x86)\Microsoft XDE\1.0\XDE.exe"
- Tick Public / Private Network or both as you are connected to internet.
精彩评论