locked
How to get web response with PrioritizedWebClient class in Bing Map App? RRS feed

  • Question

  • I am trying to retrieve string from some web page in my Bing Map App. If I correctly understand concept, I have to use NetworkManagerContract, create PrioritizedWebClient object with CreatePrioritizedWebClient() method, call DownloadStringAsync() method and in DownloadStringCompleted event handler get text result from PrioritizedDownloadStringCompletedEventArgs object. But at the end I only get following error: "Error in EndGetResponse".
    Can you please provide sample how to retrieve string from simple web page.
    Also, I cannot debug my app. I am using Map App Template Projectm,but when I start debugging as described in CHM, all I got is ASP.NET started server and redirection to http://www.bing.com/Error.aspx?aspxerrorpath=/default.aspx page ("That web page doesn't exist."). Is this correct way to start debugging or I have to configure somatehing else in project in order to succesiful debug app.
    Update
    Here is my code: 
    In plugin class I declared following:
    [ImportSingle("Microsoft/NetworkManagerContract", ImportLoadPolicy.Synchronous)]
    public NetworkManagerContract NetworkManagerContract { get; set; }
    private PrioritizedWebClient webClient; 

    In Intitialize method:
    webClient = NetworkManagerContract.CreatePrioritizedWebClient();
    webClient.DownloadStringCompleted += webClient_DownloadStringCompleted;
    webClient.DownloadStringAsync(new Uri("http://www.mydomain.com/data.txt"));

    And this is error handler which raises error:
    private void webClient_DownloadStringCompleted(object sender, PrioritizedDownloadStringCompletedEventArgs e)
            {
                if (e.Error == null)
                    string data = e.Result;
                else
                	MessageBox.Show(e.Error.Message);
            }
    Thanks,
       Wrda

    • Edited by Niko_Vrdoljak Monday, December 5, 2011 8:03 AM Code added
    Sunday, December 4, 2011 9:46 PM

Answers

  • The domain that you're trying to access needs to have the clientaccesspolicy.xml (or crossdomain.xml for Flash) in place in order for it to work.  That is, if you're trying to access data on www.foo.com, then the owner of www.foo.com has to ensure that www.foo.com/clientaccesspolicy.xml is in place and provides access to Silverlight applications.

    Our APIs hosted on dev.virtualearth.net already do have a proper clientaccesspolicy to allow calls from Silverlight, as you noted.

    The only other alternative is to proxy the call via a domain/server you do control, and then do a server-to-server call to fetch the data. That will only require the clientaccesspolicy.xml file on the first domain (which you own/control) and not on the ultimate domain you're getting data from.

    • Marked as answer by Niko_Vrdoljak Tuesday, December 6, 2011 7:36 AM
    Monday, December 5, 2011 10:50 PM

All replies

  • Your overall approach here looks sound, and I have a couple of suggestions to figure out why it isn't working properly.

    For the network request, Silverlight requires that all cross domain calls contain a clientaccesspolicy.xml at the root of the domain you're calling. Can you verify whether this is in place for your domain? More information is available here: http://msdn.microsoft.com/en-us/library/cc197955(v=VS.95).aspx

    One helpful tool for debugging network requests is Fiddler (http://www.fiddler2.com/fiddler2/), if you run this while you test your app it will log the traffic for you and give you a better idea of what is going on with the request.

    Regarding the debugging issue--I believe you're hitting a known issue that we are aware of. We're hoping to have a fix out for it next week, but in the meantime if you modify the debugging URL to add a "&sty=r" parameter to the URL, that should clear things up.

    Dan

    Monday, December 5, 2011 5:00 PM
  • It is definitely cross domain issue. For example I can download data from dev.virtualearth.net domain (e.g. http://dev.virtualearth.net/clientaccesspolicy.xml). Request to any other domain ends with "Error in EndGetResponse" error.

    I am deploying XAP file to http://www.bing.com/maps/explore/?developer=1 to Bing Map Apps via "Map app test tool", so in this case I cannot do much, although I tried all combinations with clientaccesspolicy.xml and crossdomain.xml files in SilverLight Map App project. Domain is yours. So, is there any other solution to get data from other domains?

    Monday, December 5, 2011 7:31 PM
  • The domain that you're trying to access needs to have the clientaccesspolicy.xml (or crossdomain.xml for Flash) in place in order for it to work.  That is, if you're trying to access data on www.foo.com, then the owner of www.foo.com has to ensure that www.foo.com/clientaccesspolicy.xml is in place and provides access to Silverlight applications.

    Our APIs hosted on dev.virtualearth.net already do have a proper clientaccesspolicy to allow calls from Silverlight, as you noted.

    The only other alternative is to proxy the call via a domain/server you do control, and then do a server-to-server call to fetch the data. That will only require the clientaccesspolicy.xml file on the first domain (which you own/control) and not on the ultimate domain you're getting data from.

    • Marked as answer by Niko_Vrdoljak Tuesday, December 6, 2011 7:36 AM
    Monday, December 5, 2011 10:50 PM
  • Thank you very much for your answer. Services that I want to connect are public services outside of my domain, so I will probably impement this proxy solution.

    Update:
    It works with proxy service on my domain.

    Tuesday, December 6, 2011 7:38 AM
  • Great, glad to hear you have it working now! Let us know if you have any further issues.
    Tuesday, December 6, 2011 5:44 PM