tomkuijsten / restup

Webserver for universal windows platform (UWP) apps
MIT License
114 stars 48 forks source link

Wiki update request #127

Open dm-CaT opened 7 years ago

dm-CaT commented 7 years ago

Hello.

At last I found how to configure local environment to run app with Restup server locally without any device. I think it will be useful to put this information into Wiki. I'm not familiar with GitHub Wiki maybe someone can help with it or just copy-paste the following guide?

There are two steps to configure an environment.

  1. https://developer.microsoft.com/en-us/windows/iot/docs/embeddedmode configure Embedded Mode for Windows 10 (follow Changing the mode step-by-step guide). This will allow to start UWP application with IoT library referenced locally. But the server will not be accessible from local machine (e.g. http://localhost:8080) because of local loopback prohibiting. Make sure you changed solution target platform from ARM to X64.
  2. Enable local loopback for debug sessions https://msdn.microsoft.com/en-us/library/windows/apps/hh780593.aspx Run in command-line: CheckNetIsolation.exe LoopbackExempt -s You'll get a list of IoT applications registered similar to
    
    List Loopback Exempted AppContainers

[1] ----------------------------------------------------------------- Name: IoTCoreDefaultApp_1w720vyc4ccym SID:


Now you have to run debugging session with loopback enabled:
`CheckNetIsolation.exe LoopbackExempt -is -n=IoTCoreDefaultApp_1w720vyc4ccym`
That's all. Now you can open your web application from local machine: http://localhost:8080. Don't forget to set correct port which is specified in HttpServerConfiguration.ListenOnPort(8080) method.

You can also configure auto startup of loopback enabling via scheduled tasks:
`schtasks /create /tn MyTask /f /sc onstart /ru system /tr "checknetisolation LoopbackExempt -is -n=IoTCoreDefaultApp_1w720vyc4ccym"`
tomkuijsten commented 7 years ago

Kudos for finding this solution 👍 . It would be great if we could add this to our FAQ or a separate page. Any suggestion on where to put it? And could you format the text a bit to be used as Wiki info?

dm-CaT commented 7 years ago

OK, I'll try.

dapug commented 6 years ago

This solution didn't solve it for me. I followed it carefully. Is there something else needed in current builds of Windows?

dm-CaT commented 6 years ago

I didn't try to repeat it for a long time. Maybe something changed. Which Windows version do you have? Did you face some errors or something like that on some step of the guide?

dapug commented 6 years ago

Im on Win10 build 17134.165. No error, I just simply can't make a request (for example, from browser to my UWP app listening on 8800). I get a 400.

Worked ok on an older Win10 machine, so I know RestUp and my little test app is ok (been using it a while, its great).

dapug commented 6 years ago

Resolved. I had two apps with different port settings I was working with and the failure was simply due to the request going nowhere.

New problem: There is a huge 20 second delay for Restup to respond to any request, even a simple hello-world GET request. I may need to open a new issue.

agrath commented 5 years ago

//https://stackoverflow.com/a/33263253/647728

For a line of business app use the checknetisolation.exe tool to grant the app a loopback exception.

To enable loopback use this command:

c:>checknetisolation loopbackexempt -a -n= To disable loopback use this command:

c:>checknetisolation loopbackexempt -d -n= The package family name for a UWP app can be found in several places: Visual Studio shows it in Package.appxmanifest editor on the packaging tab, PowerShell's get-appxpackage cmdlet displays it, etc. It will look something like "MyPackage_edj12ye0wwgwa"

agrath commented 5 years ago

I would like to add to this - even with the loopbackexempt as per my above comment, I still could not get the StreamSocketListener to accept incoming connections from my local machine into the UWP app running locally. I tried with postman and chrome, both the -is and -a methods of adding the loopback exemption (with the correct program) I also made sure my wifi on my laptop was set to a private network, disabled the firewall.

The note on this page is very subtle: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/StreamSocket

Note Network communications using an IP loopback address cannot normally be used for interprocess communication between a UWP app and a different process (a different UWP app or a desktop app) because this is restricted by network isolation. Network communication using an IP loopback address is allowed within the same process for communication purposes in a UWP app

You cannot use the loopback exemption to connect between processes/apps - only within the same app as a loopback exemption. I have tested the server connecting from a different PC on the local network and can confirm it accepts connections fine now :) So now testing using teamviewer to my other machine ;)