繁体   English   中英

"无效的主机名 - 无法从 Android 模拟器连接 IIS express"

[英]Invalid HostName - Not able to connect IIS express from Android Emulator

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

服务的本地 URL 是http:\/\/locahost:40000\/api\/Authenticate<\/code>

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

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

我尝试了其他有用的东西,我在IIS Express applicationhost.config文件绑定部分中添加了我的系统的IP地址。

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

我现在可以打电话给服务了

据我了解,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文件夹中。

Visual Studio 2022<\/strong>上的.NetCore<\/strong>项目中,

我编辑了launchSettings.json<\/strong>文件,在 iisSettings > applicationUrl 下,我将 url 设置为127.0.0.1<\/code>而不是localhost<\/code> ,类似这样。

"iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://127.0.0.1:59109",
      "sslPort": 0
    }
  }
  1. 什么是“端口40000”???????
    肯定会尝试更低端口号(如32768以下;))
  2. 确保您的androidmanifest.xml具有Internet权限
  3. 确保在IIS中定义并提供“api / authenticate”
  4. 确保Windows防火墙未阻止端口40000
  5. 有用的工具包括:
    • ping(所以你可以“ping 10.0.0.2”;在OOTB Windows中可用)
    • telnet(所以你可以“telnet localhost NNN”;你必须在Windows功能中添加它)
    • Firefox和Firebug
    • Wireshark的

在AndroidManifest.xml中添加Internet PermissionNetwork StateWifi 权限

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM