Get Xamarin Android Device calling ASP.NET Web APi running Localhost

天涯浪子 提交于 2020-01-02 06:58:11

问题


I've managed to use the following guide for enabling my VS2015 Android Emulator access to a ASP.NET WEP API running on my local-host which is great :-

http://briannoyesblog.azurewebsites.net/2016/03/06/calling-localhost-web-apis-from-visual-studio-android-emulator/

But i would also like to configure my Xamarin application for enabling my external android device the same access to the web api.

At present, when running from device, the webclient makes the request but it never completes, which leaves the application hanging.

Does anyone know how I can achieve this?


回答1:


Check your applicationhost.config, find the bindings for your WebApi. There should be something like this:

<binding protocol="http" bindingInformation="*:<your-port>:localhost" />

Add a binding for external requests:

<binding protocol="http" bindingInformation="*:<your-port>:*" />

Then your device can make requests to

<your-network-IP-of-your-machine>:<your-port>

Your device and your machine hosting the WebApi needs to be in the same network, e.g. your local WiFi.



来源:https://stackoverflow.com/questions/42365046/get-xamarin-android-device-calling-asp-net-web-api-running-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!