开发者

Problem accessing localhost URI from Silverlight

(repost because of SO outage; apologies if the other one re-appears)

I'm building a Silverlight app that will run on Azure. My VS solution has two projects: the web role and the Silverlight. The web role has a Service that works. (I can go to localhost:88/expenseservice.svc/expenses and get the data I want.)

I am trying to access that data from 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;
        }

        // ...

    }

However, this does not work. The message box shows the error:

开发者_JAVA百科

The URI prefix is not recognized.

Here is the full exception:

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)}

Is it complaining about localhost? Am I supposed to be doing something differently? Perhaps this is what "Add Service Reference" is for?


I think the prefix is not recognized because it is missing. The prefix should be the first part that describes what kind of service your URI is pointing to. For example http:// of svn:// and so on..

Just add the right one and it should work.. (I've never used Silverlight neither anything Microsoftish so I'm just guessing)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜