问题
private void button2_Click(object sender, RoutedEventArgs e)
{
WebClient wb = new WebClient();
wb.DownloadStringCompleted += new DownloadStringCompletedEventHandler(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.
回答1:
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.
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/4562887/not-able-to-connect-to-webservice-from-a-wp7-emulator