views:

37

answers:

1

(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:

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?

+1  A: 

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)

Jack
What prefix do I want for localhost? http://localhost?
Rosarch
I think you are not getting the point. What kind of service is online over port 88? a webserver?
Jack
This can help: http://stackoverflow.com/questions/2246735/silverlight-webrequest-fails-with-the-uri-prefix-is-not-recognized
Jack
@Jack haha I'm definitely not getting the point. It's an ASP web role hosted on the Azure dev server.
Rosarch
adding `http://` to the beginning solved it. Thanks.
Rosarch