【问题标题】:ASP.NET web application unable to connect to WCF hosted as windows serviceASP.NET Web 应用程序无法连接到作为 Windows 服务托管的 WCF
【发布时间】:2012-12-19 20:39:49
【问题描述】:

我们有一个 WCF 服务作为 Windows 服务托管,在我们的应用服务器上具有 tcp 绑定。我们有一个 ASP.NET Web 应用程序托管在尝试连接到它的单独 Web 服务器上。两台服务器都是 Windows 2008 R2 机器。

ASP.NET Web 应用程序的应用程序池设置为使用 ApplicationPoolIdentity 作为它的用户。当我们尝试从 windows 机器连接到 WCF 服务时,会出现以下错误:

Source Exception: System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:09.9980000'. ---> System.IO.IOException: The read operation failed, see inner exception. ---> System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:09.9980000'. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)

但是,当我们将应用程序池的用户更改为网络服务时,它会正确连接。

我的问题有两个。有谁知道为什么使用 ApplicationPoolIdentity 不起作用,是某种配置问题吗?而且,在网络服务帐户下运行应用程序池会有什么缺点?我知道 ApplicationPoolIdentity 的权限更少,更安全,被认为是最佳实践。

【问题讨论】:

    标签: wcf


    【解决方案1】:

    这个问题的答案取决于您在网络、服务器和服务中的不同配置。

    过去我遇到过类似情况,ApplicationPoolIdentity 无权与机器外的资源进行“对话”。

    另一个问题可能是关于如何处理 Web 应用程序和服务器之间的连接。您是每次都重复使用相同的连接,还是要关闭/重新打开您的频道? This msdn thread 有这方面的一些信息。

    【讨论】:

    • 这很好,ASP.NET Web 应用程序每次都会打开和关闭到 WCF 服务的连接。这个特殊的特性没有得到足够的使用来证明维持持久连接是合理的。看起来 ApplicationPoolIdentity 无权与外部资源交谈,就像您的情况一样。你能解决这个问题吗?
    • 在我的例子中,是域策略阻止了这种情况,因此我们切换到将应用程序池作为专用域帐户运行。不确定您的环境是什么样的,但请检查防火墙配置。
    • 我们必须检查一下。感谢您的帮助。
    • @bwalk2895 你有没有发现该设置的配置位置?
    猜你喜欢
    • 2011-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    相关资源
    最近更新 更多