none
Access localhost using xhr

    Question

  • I'm trying to build a simple metro app that pulls data from an OData service.  I've built the OData service using Visual Studio 2010 and the Entity Framework and have deployed and tested it successfully (using IE) on the Win 8 Samsung tablet.

    For some reason, my metro app is not able to connect to the OData service on localhost - the xhr promise consistently returns an "error", with the request status of 0.

    I'm confident that my code is correct as I can substitute the request uri with an external one (netflix) and it connects every time.  I can also access the localhost uri using Internet Explorer.

    Is there some restriction from being able to access localhost (neither 127.0.0.1 nor the computer name work either)?

    Mike Pearce

    Friday, October 07, 2011 6:10 PM

Answers

All replies

  • Access to the local computer is blocked for Metro Style applications.  This is part of the security.


    Jeff Sanders (MSFT)
    • Marked as answer by MikePearce Friday, October 07, 2011 6:46 PM
    Friday, October 07, 2011 6:22 PM
    Moderator
  • It seems to me that I ought to be able to specify a capability that would allow me to do this, much the same way that I can specify access to the document or picture library.


    Mike Pearce
    Friday, October 07, 2011 6:27 PM
  • Interesting idea.  I would think having this capability would also break your app if it was deployed to a smaller device (think tablet) that does not have a localhost webservice though.  Also you cannot package the Metro app with a service so you would have no way to deploy this.  What about hosting your service out on the Web?  That would retain the functionality of your application and not require anything to be hanging off the box you are running on.


    Jeff Sanders (MSFT)
    Friday, October 07, 2011 6:40 PM
    Moderator
  • Ultimately I will likely do something along those lines.  I'm dealing with a corporate network and corporate data, so I can't host it on the web, but I could host it on our internal network.

    For now, however, I don't have the tablet connected to our network (security issues - smart cards, etc.), so I'm creating local copies of the data directly on the Samsung tablet.  I've set up IIS and SQL Server so that everything can run without the tablet needing to be connected.

    I guess for now I'm going to have to read the data directly from the database rather than using OData.


    Mike Pearce
    Friday, October 07, 2011 6:45 PM
  • Mike,

    For testing purposes you could disable the loopback check using (CheckNetIsolation.exe):

    http://msdn.microsoft.com/en-us/library/windows/apps/hh452759%28v=VS.85%29.aspx

    -Jeff


    Jeff Sanders (MSFT)
    Monday, October 10, 2011 6:21 PM
    Moderator
  • Use IIS and port your site on port 80 by using default web site option
    Monday, December 26, 2011 12:14 PM
  • Quick question:shouln't it work if you use the name of the machine? for instance, instead of specifying http://localhost/someurl, can we use http://machinename/someurl?

    the reason I'm asking this is because I'm building a small simple metro app which will only be used in the internal network and it needs to access several local Web services.

     

    thanks.


    Luis Abreu
    Wednesday, January 04, 2012 10:38 PM
  • No sorry!  This is blocked.
    Jeff Sanders (MSFT)
    Thursday, January 05, 2012 1:15 PM
    Moderator
  • I was able to get this to work using a combination of 2 solutions.

    First, I used the answer that Jeff provided in regards to the CheckNetIsolation utility and disabled the loopback check (http://msdn.microsoft.com/en-us/library/windows/apps/hh452759%28v=VS.85%29.aspx).

    I also had to modify the firewall rules to allow incoming HTTP connections over port 80.

    Once both were done I have been able to successfully access a web service that is hosted locally in IIS.

    Mike Pearce


    Mike Pearce
    • Marked as answer by MikePearce Thursday, January 05, 2012 1:39 PM
    Thursday, January 05, 2012 1:38 PM
  • Thank you!

    That's it!


    Luis Abreu
    Thursday, January 05, 2012 1:48 PM
  • Thanks Mike,

    Yes that will work fine for testing.  Luis, if you intend to deploy the app, you can see how this would be a problem right?

    -Jeff


    Jeff Sanders (MSFT)
    Thursday, January 05, 2012 1:58 PM
    Moderator
  • Yes, I do. But it's what I need for testing purposes..
    Luis Abreu
    Monday, January 09, 2012 12:49 PM
  • Hi,

     

    Is there any official document to list these kind of limitation that we developer can lookup as a check list? Thanks.

    Tuesday, January 17, 2012 11:49 PM