【问题标题】:Azure Website Local Call WebExceptionAzure 网站本地调用 WebException
【发布时间】:2014-03-04 09:17:17
【问题描述】:

我正在尝试使用 Phantom 和 Selenium 在 Azure 中调用我自己的网站。

它可以在本地工作,但是当我将它部署到 Azure 时却不能,这会导致以下异常:

意外错误。 System.Net.WebException:无法连接到远程服务器--->

System.Net.Sockets.SocketException: 
              An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:49888

at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)

at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)

Exception Details: OpenQA.Selenium.WebDriverException: Unexpected error. System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:49888

(Fuller trace)

我想我可能需要添加防火墙规则或其他东西,但我真的不确定。该网站是 Azure 网站。

如果我可以在不涉及服务器配置的情况下从 C# 代码中解决这个问题 - 那会更可取。

【问题讨论】:

  • 49888 是您的站点可用的实际端口,还是 selenium 试图在这里设置某种控制?您对 localhost 与公共主机名的使用有影响吗?
  • @SimonOpelt 49888 是 selenium 用来连接驱动程序的端口。任何解决方案都是可以接受的,我对端口号 49888 没有任何意见:)
  • 反对者解释为什么?

标签: c# asp.net-mvc azure selenium azure-web-app-service


【解决方案1】:

我假设我遇到了同样的问题,但是,在其他一些场景中,我需要从后台工作线程向网站的公共界面发出 Web 请求。在本地它可以工作,但是一旦部署在 Azure 中,请求就开始抛出由 SocketException 引起的 WebException

虽然我不需要以任何方式处理 Web 响应,但这里的解决方案是将 Web 响应存储在堆栈中,并通过调用其 Close() 方法正确处理:

HttpWebResponse response = null;

try {
    var webReq = WebRequest.CreateHttp(url);
    webReq.Method = "GET";
    response = (HttpWebResponse)webReq.GetResponse();
}
finally {
    if (response != null) response.Close();
}

异常从请求 #249 开始稳定(前 248 个请求没有抛出异常)。因此,我假设某种 Web 请求或 Web 响应池正在后台进行,并且不对响应对象调用 Close() 可能会在某些时候或在特定条件下耗尽该池。

【讨论】:

  • 使用using 可能会更好。感谢您的回答,但我认为这不是我们遇到的问题。
猜你喜欢
  • 1970-01-01
  • 2012-10-16
  • 1970-01-01
  • 2012-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-09
  • 1970-01-01
相关资源
最近更新 更多