c#:无法建立与服务器的连接
c# : A connection with the server could not be established
我知道这个问题已被问过多次,但找不到与我的情况完全匹配的内容。
我有 2 个 Web APIs,比如 WebAPI1 和 WebAPI2。 WebAPI1 使用.Netcore 开发,部署在Azure 中。 WebAPI2 使用 .NET Framework 4.6.1 开发,并使用 IIS 部署在 Azure VM 中。
现在我必须从 WebAPI1 向 WebAPI2 发出请求。我已经使用 httpclient 调用了 WebAPI2。
托管后,尝试发出请求时,抛出以下错误:
the connection with the server could not be established.
我已将虚拟机的端口 80 和 443 添加到入站端口规则中。那并没有解决我的问题。我猜这可能是防火墙问题。我可以尝试解决什么问题?
编辑
我的 VM 的 IP 地址类似于 10.x.x.x。在 IIS 中,我在默认网站中添加了一个应用程序,名称为:WebAPI2
。在网络中 API 我有控制器方法名称 GetData()
.
我有路由前缀:[RoutePrefix("api/App")]
。所以我使用的 URL 是 http://10.x.x.x/WebAPI2/api/App/GetData
.
请确保您已经为iis网站(WebAPI2)绑定了域名或者直接使用指定端口的虚拟机IP
您似乎无法使用 URL http://10.x.x.x/WebAPI2/api/App/GetData
从 Azure Web 应用服务中的 WebAPI1 访问 Azure VM 上的 WebAPI2,因为 public Azure Web 应用服务找不到URL.
中的私有 IP
在这种情况下,您可以在 Azure 网络应用服务中启用 VNet integration。这使你的 Web 应用程序可以访问虚拟网络中的资源,但不会授予从虚拟网络对你的 Web 应用程序的私有访问权限。此外,这些网络随后可以使用 VPN 技术连接到您的本地网络。
此外,如果 Azure Web 应用程序设置了他们的 VNet,某些 Networking Restrictions/Considerations 在 Azure Web 应用程序沙箱中可能会有所不同。
In particular, the restrictions on private and local
addresses are ignored if the target network interface belongs to the
app. Other VNet adapters on the same machine cannot be accessed, and
all other network limitations are still apply.
我知道这个问题已被问过多次,但找不到与我的情况完全匹配的内容。
我有 2 个 Web APIs,比如 WebAPI1 和 WebAPI2。 WebAPI1 使用.Netcore 开发,部署在Azure 中。 WebAPI2 使用 .NET Framework 4.6.1 开发,并使用 IIS 部署在 Azure VM 中。
现在我必须从 WebAPI1 向 WebAPI2 发出请求。我已经使用 httpclient 调用了 WebAPI2。
托管后,尝试发出请求时,抛出以下错误:
the connection with the server could not be established.
我已将虚拟机的端口 80 和 443 添加到入站端口规则中。那并没有解决我的问题。我猜这可能是防火墙问题。我可以尝试解决什么问题?
编辑
我的 VM 的 IP 地址类似于 10.x.x.x。在 IIS 中,我在默认网站中添加了一个应用程序,名称为:WebAPI2
。在网络中 API 我有控制器方法名称 GetData()
.
我有路由前缀:[RoutePrefix("api/App")]
。所以我使用的 URL 是 http://10.x.x.x/WebAPI2/api/App/GetData
.
请确保您已经为iis网站(WebAPI2)绑定了域名或者直接使用指定端口的虚拟机IP
您似乎无法使用 URL http://10.x.x.x/WebAPI2/api/App/GetData
从 Azure Web 应用服务中的 WebAPI1 访问 Azure VM 上的 WebAPI2,因为 public Azure Web 应用服务找不到URL.
在这种情况下,您可以在 Azure 网络应用服务中启用 VNet integration。这使你的 Web 应用程序可以访问虚拟网络中的资源,但不会授予从虚拟网络对你的 Web 应用程序的私有访问权限。此外,这些网络随后可以使用 VPN 技术连接到您的本地网络。
此外,如果 Azure Web 应用程序设置了他们的 VNet,某些 Networking Restrictions/Considerations 在 Azure Web 应用程序沙箱中可能会有所不同。
In particular, the restrictions on private and local addresses are ignored if the target network interface belongs to the app. Other VNet adapters on the same machine cannot be accessed, and all other network limitations are still apply.