现有连接被远程主机强制关闭

发布于 2024-09-02 05:27:23 字数 2091 浏览 2 评论 0原文

我有一个胖 VB.NET Winform 客户端,它使用旧的 asmx 样式 Web 服务。通常,当我执行需要一段时间的查询或将大量数据传递到数据集中的 Web 服务时,我会收到主题错误。

该错误似乎发生在< 1 分钟,远小于我设置的 Web 服务超时值或在 Web 服务器内执行查询的 ADO Command 对象上的超时值。

每当我执行一个期望返回大量行的大型查询或者当我向 Web 服务发送大量数据时,似乎就会发生这种情况。例如,当我将一个大型数据集传递到网络服务器时,就发生了这种情况:

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
   --- End of inner exception stack trace ---
   at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at Smit.Pipeline.Bo.localhost.WsSR.SaveOptions(String emailId, DataSet dsNeighborhood, DataSet dsOption, DataSet dsTaskApplications, DataSet dsCcUsers, DataSet dsDistinctUsers, DataSet dsReferencedApplications) in C:\My\Code\Pipeline2\Smit.Pipeline.Bo\Web References\localhost\Reference.vb:line 944
   at Smit.Pipeline.Bo.Options.Save(TaskApplications updatedTaskApplications) in 

我一直在查看大量有关此错误的帖子,令人惊讶的是导致此错误的情况多种多样。我尝试过使用 Wireshark,但我不知道如何使用它。

这个应用程序在任何时候只有大约 20 个用户,我能够在半夜重现这个错误,当时可能没有人使用该应用程序,所以我不认为对 Web 服务器的请求数量或对数据库来说是高的。我可能是现在唯一使用该应用程序的人,我现在刚刚收到错误。它似乎必须对任一方向传递的数据量进行所有处理。

I have a fat VB.NET Winform client that is using the an old asmx style web service. Very often, when I perform query that takes a while or pass a large amt of data to a web service in a dataset, I get the subject error.

The error seems to occur in < 1 min, which is far less than the web service timeout value that I have set or the timeout value on the ADO Command object that is performing the query within the web server.

It seems to occur whenever I am performing a large query that expects to return a lot of rows or when I am sending up a large amount of data to the web service. For example, it just occurred when I was passing a large dataset to the web server:

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
   --- End of inner exception stack trace ---
   at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at Smit.Pipeline.Bo.localhost.WsSR.SaveOptions(String emailId, DataSet dsNeighborhood, DataSet dsOption, DataSet dsTaskApplications, DataSet dsCcUsers, DataSet dsDistinctUsers, DataSet dsReferencedApplications) in C:\My\Code\Pipeline2\Smit.Pipeline.Bo\Web References\localhost\Reference.vb:line 944
   at Smit.Pipeline.Bo.Options.Save(TaskApplications updatedTaskApplications) in 

I've been looking a tons of postings on this error and it is surprising at how varied the circumstances which cause this error are. I've tried messing with Wireshark, but I am clueless how to use it.

This application only has about 20 users at any one time and I am able to reproduce this error in the middle of the night when probably no one is using the app, so I don't think that the number of requests to the web server or to the database is high. I'm probably the only person using the app right now and I just got the error now. It seems to have to do everything with the amount of data being passed in either direction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

爱情眠于流年 2024-09-09 05:27:23

检查客户端的 app.config 绑定设置并查看是否指定了最大消息大小。默认值为 65536

要更改此设置,请将其放入 app.config 中的绑定配置(maxReceivedMessageSize、maxBufferSize 和 maxArrayLength 是此设置的关键属性)中,或者以编程方式更改绑定上的属性,如下

System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();

// if you are getting a LOT of data back, you will need to up Message Size
binding.MaxReceivedMessageSize = int.MaxValue; 

所示不能解决您的问题,您必须检查服务器端的事件日志以获取详细信息。该消息意味着客户端并不希望连接关闭,但它确实关闭了,并且它可能意味着许多不同的事情。

如果可能,请使用 WCF 进行 Web 服务。它解决了 ASMX 服务仍然遇到的许多问题。

要增加服务器端传输限制和执行超时,请使用此

<configuration>
  <system.web> 
    <httpRuntime maxMessageLength="409600" executionTimeoutInSeconds="300"/> 
  </system.web>
</configuration> 

Check your client's app.config binding setting and see if you have specified a Max message size. The default value for this is 65536

To change this, either put it in your binding configuration (maxReceivedMessageSize, maxBufferSize and maxArrayLength are key properties for this) in your app.config, or programmatically by changing the property on the binding, like so

System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();

// if you are getting a LOT of data back, you will need to up Message Size
binding.MaxReceivedMessageSize = int.MaxValue; 

If this doesnt solve your issue, you will have to check the server side's event log for details. The message means that the client didnt expect the connection to close, but it did, and it could mean many different things.

If possible, use WCF for web services. It solves a lot of problems that ASMX services still suffer from.

To increase the server side transmission limit and execution timeout, use this

<configuration>
  <system.web> 
    <httpRuntime maxMessageLength="409600" executionTimeoutInSeconds="300"/> 
  </system.web>
</configuration> 
纸伞微斜 2024-09-09 05:27:23

我遇到了完全相同的问题。 Web 服务调用将因相同的间歇性异常(大约每天一次)而失败。它与太大的数据包大小或太小的超时无关。

我最终只是添加了一些重试逻辑来解决该问题。
请参阅:如何改进此异常重试场景?

I was having the exact same issue. Web service calls would fail with the same intermittent exception (~ once a day). It wasn't related to too large packet sizes or too small timeouts.

I ended up just putting in some retry logic which has worked around the problem.
See: How can I improve this exception retry scenario?

当梦初醒 2024-09-09 05:27:23

这段代码为我解决了这个问题:

Socket.ReceiveFrom(Buffer, Net.Sockets.SocketFlags.None, ReceiveEndpoint)
Socket.SendTo(Buffer, Length, Net.Sockets.SocketFlags.None, ReceiveEndpoint)

当我使用带有 socketsflags 的函数时,服务器/客户端没有再次断开连接。

This code solved the issue for me:

Socket.ReceiveFrom(Buffer, Net.Sockets.SocketFlags.None, ReceiveEndpoint)
Socket.SendTo(Buffer, Length, Net.Sockets.SocketFlags.None, ReceiveEndpoint)

When I used the function with socketsflags the server/client didn't get disconnected again.

逐鹿 2024-09-09 05:27:23

如果是 ASP.NET,请尝试在 web.config 文件中将 maxRequestLength 设置为更高的值,

<httpRuntime maxRequestLength="65536"/>

不要将该值增加太多,因为这可能会导致其他错误,例如拒绝访问等。
如果是向远程服务器上传数据,请尝试对数据进行切片并分块发送。

亲切的问候,

马法兹

If it is ASP.NET try setting the maxRequestLength to a higher value in the web.config file

<httpRuntime maxRequestLength="65536"/>

Do not increase the value too much as it might result in other errors like Access Denial etc.
If it is a dataupload to a remote server, try slicing the data and sending in chunks.

Kind Regards,

Mafaz

可遇━不可求 2024-09-09 05:27:23

就我而言,我的通用 HTTP 处理程序 (handler.ashx) 在尝试从 WCF 服务检索大文件时遇到连接意外断开的情况。最终,答案出现在一个 Microsoft 网页中(https://msdn .microsoft.com/en-us/library/ms733742.aspx)并致电 Microsoft,后者告诉我该页面上的一个关键项目拼写错误(应该是“Streamed”而不是“Streaming”) 。该页面中应用到我的 WCF 服务的 app.config 文件的更正代码片段如下:

<system.serviceModel>
<bindings>
    ...
    <basicHttpBinding>
    <binding name="ExampleBinding" transferMode="Streamed"/>
        </basicHttpBinding>
    </bindings>
    ...
<system.serviceModel>

关键是设置传输模式。

In my case, my generic HTTP handler (handler.ashx) was experiencing the unexpectedly dropped connection when trying to retrieve large files from a WCF service. In the end, the answer came in one Microsoft web page (https://msdn.microsoft.com/en-us/library/ms733742.aspx) and a call to Microsoft, who told me that one critical item on that page was misspelled (should have been "Streamed" instead of "Streaming"). The corrected code snippet from that page, applied to my WCF service's app.config file is this:

<system.serviceModel>
<bindings>
    ...
    <basicHttpBinding>
    <binding name="ExampleBinding" transferMode="Streamed"/>
        </basicHttpBinding>
    </bindings>
    ...
<system.serviceModel>

The key was to set the transfer mode.

抱着落日 2024-09-09 05:27:23

试试这个,它对我来说适用于通过网络流发送的 10000 个,

定义 SendBufferSize 超过当前 TcpClient 的设置或优化您的系统
如果未定义,则值为 8192,这意味着您不能发送超过此值的字节。

**YourInstantTcpClient**.SendBufferSize = 6550000

抱歉,我是泰国人,可能我的英语不好。

try this ,it work for me for 10000 sent via network stream

defind SendBufferSize more than setting of the current TcpClient or optimize to your system
if not define the value is 8192 that mean you can not send byte out more than this.

**YourInstantTcpClient**.SendBufferSize = 6550000

Sorry ,i'm thai people,may my english isn't good.

送君千里 2024-09-09 05:27:23

对于 IIS 7(在我的例子中),Web 服务的应用程序池的标识是“ApplicationPoolIdentity”。我分配给本地用户,效果很好。

For IIS 7 (in my case), the webservice's application pool's identity was "ApplicationPoolIdentity". I assigned to a local user and it worked just fine.

_失温 2024-09-09 05:27:23

好的,我遇到了同样的错误。但就我而言,问题出在 AV 软件中,该软件阻止了本地报告服务。

Okay, i got same error. But in my case the problem was in AV software, which was blocking reporting services locally.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文