How to debug a Xamarin iOS app hitting a localhost asp.net core API - xamarin

I have a Xamarin Forms app (Android and iOS, not UWP) that hits a DotNetCore 2.1 API I have created (runs under http://localhost:5000). All this is being developed using Visual Studio 2017.
I am able to debug the Android side with the address http://10.0.2.2:5000 which translates to 'localhost' on the Android side of things. So I am able to hit my API just fine from the Android simulator.
The problem is on the iOS side.
The iOS simulator is really running on the Mac, and thusly is not able to see my Windows machine running the API.
How do I configure my Windows/Mac machines so I am able to hit my local API?
I am able to ping my Windows machine from the Mac, but that's about it at this point.

I have this solved and am posting what I did to help others. I am now able to hit my .net core 2.1 web api from both the Android emulator, iOS emulator, and actual devices.
1) Run ipconfig to get your local IP address.
2) I didn't do anything special with the Program class. You can see this is the default File/New Project templated code. I saw many suggestions to use a more explicit Kestral configuration. I am sure in some scenarios it would help, but in my case this was not necessary.
3) Configure Kestral to listen on that IP and port (vs. localhost).
4) Open the firewall to pass traffic on that port.
netsh advfirewall firewall add rule name="Http Port 5000" dir=in action=allow protocol=TCP localport=5000

Related

How to deploy a UWP to a Galaxy TabPro S with windows 10 OS?

I'm trying to deploy a UWP app from my Alienware 18, Laptop with Windows 10, version 1803 to a Tablet Galaxy TabPro S with Windows 10 version 1803 as well.
I had activated developer mode on the device target and the USB device discovery option as well.
First I tried connecting a USB Cable from my laptop to the tablet which has a USB-C port.
But My laptop doesn't even find it.
What I want is to find a way to deploy a UWP from my laptop to the tablet, I made some research and I found out that, only HoloLens and Windows Phone 10, are findable using USB Connection.
So what step should I follow to successfully remote debug my app to a windows 10 Tablet.
I would appreciate details because I tried to follow remote deploying but I haven't been able to successfully find the tablet.
The Windows 10 on your tablet, just like on your development machine, supports remotely debugging over the network rather than over USB. Make sure both machines are in developer mode, with the other machine also having Device Discovery turned on as described here. Both should connect to your WiFi as a private network. After that it should be as simple as configuring your project to deploy to the other machine, rather than locally, as described here and here. Don't forget to pair them with a PIN.
If you host a web API on your development machine, configure your firewall as described here.
Use remote debugging over at https://learn.microsoft.com/en-us/visualstudio/debugger/remote-debugging?view=vs-2017
Make sure you follow the instructions, sometimes remote debugging is barred by firewall so check that.
Alternative right click your main project, go to store then click create packages for sideloading and then send the package over at your Samsung device.
So what step should I follow to successfully remote debug my app to a windows 10 Tablet.
To run a UWP app on a remote machine, you must attach to it using the Remote Tools for Visual Studio.
In some scenarios, the remote tools are automatically installed when you deploy to a remote device. For example,
For Windows 10 PCs running Creators Update and later versions, remote tools will be installed automatically.
Then, your remote device and the Visual Studio computer must be connected over a network or connected directly through a USB or Ethernet cable. Debugging over the internet is not supported.
After that, you need to configure the Visual Studio project for remote debugging. In the properties of the project, select the Debug and choose the Remote Machine from the Target Device list. In general, I will input the remote machine's IP address, you could choose Find to choose the device from the Select Remote Debugger Connection dialog box.
Next step, please move to your Tablet, you need to Set up the remote debugger. You must have administrative permissions on the remote computer. Then, open the Start menu and search for Remote Debugger. If you could find it, just start it normally. If you cannot find it, you need to install it Remote Tools manually. See this link to Download and Install the remote tools. Once the Remote Debugger started, you could do some configurations. After that, you could choose Start Debugging on the Debug menu (Keyboard: F5). The project is recompiled, then deployed to and started on the remote device. Please read Run UWP apps on a remote machine in Visual Studio for more information.

ECONNREFUSED - Cannot connect from Android Studio to a Node.js web app on the same PC

I am developing an app in Android Studio and it makes Http calls to a Node.js web application that I am developing in Visual Studio. All these are on the same Windows 10 PC now.
The Node.js web app is running via Visual Studio 2017 and listening at port 1337. I am able to connect to localhost:1337/ from both Chrome and Edge and verify that the Node.js app is running well. However, from the Android app running in an Android emulator, when trying to connect to localhost:1337/ it got:
Exception: failed to connect to localhost/127.0.0.1 (port 1337): connect failed: ECONNREFUSED (Connection refused)
I disabled the Windows Firewall, but the same problem is still there.
If I deploy the Node.js app to a real web site on AWS, the Android app in the emulator is able to connect to that and work as expected. The downside is that I am unable to step through the Node.js app to debug.
So, on its own, the Node.js app is running fine on my PC and browsers can connect to it. On its own, the Android app is running fine on my PC, and able to connect to the Node.js app on the Internet. The problem is the Android app cannot talk to the Node.js app on the same PC.
Does the problem lie in Visual Studio, Windows or Android Studio?
As said before: localhost (127.0.0.1) is your emulator not your local computer.
check this.
How to connect to my http://localhost web server from Android Emulator in Eclipse
so use either the IP address of your computer or 10.0.2.2, which is a special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)
I think , localhost didn't work from android studio, because from emulator android studio you cannot direct access
you might be use 10.0.2.2 or 10.0.3.2 , may be this can help you
:)
Use your PC IP address. Run ifconfig/ipconfig in terminal/command prompt and look for something like an inet (or whatever looks like an IP address)
Right click on windows icon at extreme bottom left and select windows-shell or cmd and type ipconfig->enter. As it is the same conputer that Node.js is running, use the ipV4 address of ethernet adapter shown, instead of localhost in your app. Hope this helps...

Development environment does not see my phone

I\'m trying to debug the application via usb on my phone, but the development environment does not see my phone (Chperia Z compact e5823). The driver was updated, the developer mode was enabled, USB debugging is enabled. What could be the problem?
Possible problems:
Android SDK not setup or incorrectly setup
adb not setup or incorrectly setup
Also there are some "packages" you need to (should) install inside the android sdk manager. The Google USB Drivers, for example, is one of them.

Windows Mobile device not connecting to VS2008 using CoreCon/RDB2008

I am trying to connect a Windows Mobile 5.0 device with Visual Studio 2008 using Corecon (tried all processor architecture files available inside wce400 folder) and RDB2008, but it won't connect. Here is the device details page:
Does anyone have any idea what could be wrong here? I suspect a mix-up of Device OS, architecture and SDK. Appreciate any effort or help on this. Thanks.
Remote debug within VS2008 for a Windows Mobile device needs a valid IP connection with the debug ports (5655) opened (if a firewall is active).
First try to start a debug session with a simple .NET Compact Framework application (a C# SmartDevice project) and the device is connected via USB ActiveSync/WindowsMobileDeviceCenter. If that does not work, you are in trouble. Does the device connect to Windows Mobile Device Center? Try Start>Settings>Connections>USBtoPC setting change on the device.
If you can 'debug' using an USB connection but not using WiFi, check subnet and ports and Internet connection setting for Wireless Card on the device. Can you ping the device from the VS2008 PC? Can you ping the VS2008 PC from the device (vxUtils ping)? Is the debug port opened on the device after RDB2008.exe started and installed (see my NetStat for Windows Mobile)?
You may try a network trace on the VS2008 PC to see what happens on port 5655. Or even a network trace on the device (MS powertoys NetAnalyze).
I assume you followed this

Visual Studio is setting up my Azure web role to 127.255.0.0:82 instead of 127.0.0.1:80

I have Windows Azure SDK 1.6 installed along with Azure tools. I have one web role (with two endpoints, port 80 for http and port 443 for https) and only have one instance of the web role running (for testing purposes).
When I ran it from Visual Studio for debugging last week, it ran the emulator, attached it to IIS with a binding of 127.0.0.1:80 and everything was peachy.
But as of yesterday, as soon as I started it was trying to bind it to 127.255.0.1:82 and it stopped working with this error (from Visual Studio):
There was an error attaching the debugger to the iis worker process
for URL 'http://127.255.0.0:82'
Now if I manually go to IIS and change the bindings back, I can access the site through a browser but obviously I can't debug it via VS.
Why is Visual Studio doing this? What made it change from last week (I've only made code changes and I have commented them out)?
Edit: I know about this blog, but my issue seems to be different because for one reason I don't have errors in the event logs. And like I mentioned as soon as I change the bindings manually in IIS, I can access the site properly so the app pool is configured correctly.
Edit2: I have the following set:
<compilation debug="true" targetFramework="4.0" />
And my cloud project is set to startup project as well.
When I ran it from Visual Studio for debugging last week, it ran the
emulator, attached it to IIS with a binding of 127.0.0.1:80 and
everything was peachy.
I don't believe you ever debugged a Azure Emulator deployed project on 127.0.0.1:80 binding with IIS. There is a chance that what you've debugged is just the Web Application project and not the Azure Deployed one. Let me explain why:
Windows Azure Emulator uses internal emulated Load Balancer (LB).
This emulated LB binds to 127.0.0.1 port 80 (if port 80 is already
taken it uses port 81)
Windows Azure Tools are dynamically creating a virtual IP address
for every instance of a webrole you have. These dynamic IP Addresses
are 127.255.0.X, where X is the logical number of the instance (0,
1, 2, etc...).
Windows Azure tools creates a website in the local IIS, with binding
of 127.255.0.X and port 82
Step 3 is repeated for every instance you have defined.
When start debugging, your browser usually opens http: //127.0.0.1:81/ which is the address of the LB. But the request from this address is forwarded to the IIS and its binding to 127.255.0.X:82. You could not have debugged a Windows Azure Emulator deployed project by manually attaching debugger to 127.0.0.1:80, because, if everything was fine there is no w3wp process listening on that address:port, but Azure emulated LB.
When you only have the WebRole (no additional sites defined), Windows Azure Tools does know that it shall attach the debugger to 127.255.0.X:82 where a w3wp process is listening.
This is the clean working configuration of Azure Emulator & SDK & Tools v.1.6 (I think also 1.5 and even back to 1.3 where the Full IIS mode was introduced for first time)
Now if I manually go to IIS and change the bindings back, I can access
the site through a browser but obviously I can't debug it via VS.
Yes, you will be able to access the site, but in that way you are skipping the emulated LB, which is not the point when developing Windows Azure Applications.
If you are heving issues of that kind, I suggest that you clean your solution, restart the computer, and if the problem persist uninstall the SDK & Tools and perform clean full install of SDK & Authoring tols for Windows Azure v.1.6 using the Web Platform Installer.

Resources