【问题标题】:Invalid HostName - Not able to connect IIS express from Android Emulator无效的主机名 - 无法从 Android 模拟器连接 IIS express
【发布时间】:2012-08-01 16:53:11
【问题描述】:

我正在尝试从 Android 应用程序连接托管在本地 IIS express 上的 WCF 服务。目前,我正在模拟器上对此进行测试。

服务的本地 URL 是 http://locahost:40000/api/Authenticate

我知道 localhost 不起作用,我在代码中使用了 10.0.2.2

post = new HttpPost("http://10.0.2.2:40000/api/authenticate");

但客户端执行的响应是“无效主机名”

我尝试编辑 IIS express 的 ApplicationHost.config 并为 10.0.2.2 添加了一个绑定条目,但这也不起作用

我还有什么遗漏的吗?

【问题讨论】:

标签: java android asp.net-mvc android-emulator


【解决方案1】:

我尝试了其他可行的方法,我在 IIS Express applicationhost.config 文件绑定部分中添加了系统的 IP 地址。

<bindings>
<binding protocol="http" bindingInformation="*:40000:localhost" />
<binding protocol="http" bindingInformation="*:40000:192.168.5.118" />
</bindings>

我现在可以调用服务了

【讨论】:

  • 文章替换 bindingInformation,不要那样做,像@Kunal那样做并复制。
【解决方案2】:

据我了解,10.0.2.2 是 127.0.0.1 的别名,因此请将其添加到您网站的 applicationhost.config 绑定中,例如

 <site name="MySite" id="1">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
      <virtualDirectory path="/" physicalPath="{yourpath}" />
    </application>
    <bindings>
      <binding protocol="http" bindingInformation="*:26013:localhost" />
      <binding protocol="http" bindingInformation="*:26013:127.0.0.1" />
    </bindings>
  </site>

请记住,如果您现在使用 Visual Studio,您网站的相关 applicationhost.config 可能不在 c:\users\... 中,而是在解决方案根目录下的 .vs\config 文件夹中。

【讨论】:

    【解决方案3】:

    添加Internet Permission、Network State和WifiAndroidManifest.xml中的权限

    【讨论】:

      【解决方案4】:
      1. 什么是“端口 40000”???????
        我肯定会尝试使用较低的端口号(例如低于 32768 的端口号;))
      2. 确保您的 androidmanifest.xml 具有 Internet 权限
      3. 确保“api/authenticate”已定义且在 IIS 中可用
      4. 确保 Windows 防火墙未阻止端口 40000
      5. 有用的工具包括:
        • ping(因此您可以“ping 10.0.0.2”;在 OOTB Windows 中可用)
        • telnet(因此您可以“telnet localhost NNN”;您必须在 Windows 功能中添加此功能)
        • Firefox 和 Firebug
        • Wireshark

      【讨论】:

      • 我认为端口号没有问题。当我从提琴手调用 API 时,40000 有效。所有这些都适用于提琴手,但不适用于 Android。
      • 另外,我在清单文件中列出了这些权限:
      • @Paulsm4,好吧,没有必要这样做..但我仍然想提一下,每个 TCP/IP 连接都有 65536 个端口,从 0 开始计数,否则它的 65535.. 所以 40000 是相当有效的一……谢谢……
      猜你喜欢
      • 2021-05-07
      • 2017-08-04
      • 2013-07-14
      • 1970-01-01
      • 1970-01-01
      • 2014-03-06
      • 2011-10-17
      • 2019-12-23
      • 1970-01-01
      相关资源
      最近更新 更多