0
訪問本地主機URI(重新發布的,因爲SO停運;道歉,如果另一種重新出現)問題從Silverlight的
我建立一個Silverlight應用程序,將在Azure上運行。我的VS解決方案有兩個項目:Web角色和Silverlight。 Web角色具有可用的服務。 (我可以去localhost:88/expenseservice.svc/expenses
得到我想要的數據。)
我試圖從Silverlight中訪問數據:
private void MainPage_Loaded(object sender, RoutedEventArgs args)
{
WebClient data = new WebClient();
data.DownloadStringCompleted += new DownloadStringCompletedEventHandler(data_DownloadStringCompleted);
Uri dataSource = new Uri("localhost:88/expenseservice.svc/expenses");
data.DownloadStringAsync(dataSource);
}
void data_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.InnerException.Message);
return;
}
// ...
}
但是,這是行不通的。消息框顯示了錯誤:
The URI prefix is not recognized.
以下是完整的例外:
e.Error.InnerException = {System.NotSupportedException: The URI prefix is not recognized.
at System.Net.WebRequest.Create(Uri requestUri)
at System.Net.WebClient.GetWebRequest(Uri address)
at System.Net.WebClient.DownloadStringAsync(Uri address, Object userToken)}
難道抱怨localhost
?我應該做一些不同的事情嗎?也許這就是「添加服務引用」的用途?
我想要什麼前綴爲本地主機? HTTP://本地主機? – 2010-10-09 16:40:30
我認爲你沒有明白這一點。什麼樣的服務通過端口88在線?一個網絡服務器? – Jack 2010-10-09 16:43:23
這可以幫助:http://stackoverflow.com/questions/2246735/silverlight-webrequest-fails-with-the-uri-prefix-is-not-recognized – Jack 2010-10-09 16:46:03