【问题标题】:Get Xamarin Android Device calling ASP.NET Web APi running Localhost获取 Xamarin Android 设备调用运行 Localhost 的 ASP.NET Web APi
【发布时间】:2017-02-21 10:40:56
【问题描述】:

我已经设法使用以下指南使我的 VS2015 Android 模拟器能够访问在我的本地主机上运行的 ASP.NET WEP API,这很棒:-

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

但我还想配置我的 Xamarin 应用程序,以使我的外部 android 设备能够对 web api 进行相同的访问。

目前,当从设备运行时,webclient 会发出请求但从未完成,这导致应用程序挂起。

有谁知道我如何做到这一点?

【问题讨论】:

  • 你在 applicationhost.config 中设置了什么?
  • 模拟器的 Network2 适配器的 IP 地址,如教程中所述。它在模拟器上运行良好,但在物理设备上运行良好。

标签: c# asp.net-web-api xamarin xamarin.android


【解决方案1】:

检查您的 applicationhost.config,找到您的 WebApi 的绑定。应该是这样的:

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

为外部请求添加绑定:

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

然后您的设备可以发出请求

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

您的设备和托管 WebApi 的机器需要在同一个网络中,例如您的本地 WiFi。

【讨论】:

    猜你喜欢
    • 2017-08-07
    • 1970-01-01
    • 2019-03-30
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 2018-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多