I have an API server project running on my local windows machine (at the moment just running on a localhost address, can be changed).
I am then trying to test my Xamarin Forms app which tries to connect to this API on the iOS simulator.
How is it best to do this?
From googling I have found that if I was doing this all from the Mac it might just work? But how do I get this to work from Windows? If I run the UWP app, it all works as expected, because it is running all on my machine.
At present I am having to publish my API and access it that way, but that isn't the ideal way, just seems unnecessary when I'm trying to test things quickly with debugging.
Answers
I think, If your windows machine and mac machine are on same network then you might test local API calls from app.
Don't know exactly but you can try.
I have been trying, hence my question, I don't know how to get it to work.
@james1301
It would definitely help if your Windows PC is on the same subnet as your Mac. Then you would need to specify the IP address of the workstation that is running your API service instead of using localhost url (which just means the service is running on the same machine that the code is running on, which in the case of an iOS simulator "localhost" is the iOS Simulator, and I assume your service is not running on the iOS simulator :-) So you need to replace "localhost" in your code with the IP address of your Windpws PC).
Also you will need to open firewall rules on your Windows PC to allow remote access to the API service. See our guide on using WCF service with Xamarin, especially the section on configuring remote access which shows how to allow remote requests:
https://docs.microsoft.com/en-us/xamarin/cross-platform/data-cloud/web-services/walkthrough-working-with-wcf#configuring-remote-access-to-iis-express
Using the application from your own machine with localhost
When you want to test the application using an emulator with the real API using localhost, you'll need to follow a couple of steps to get things running. By default, localhost on your machine won't be accessible from the emulator (Android or iOS). Please note that several solutions exist to work around this problem, the below solution is describing the way I work.
Your Xamarin application should now be able to access the API.
Any chance this could work with https?