1

I have a ASP.NET (VB.NET) web application (targeting .NET 4 Framework) which throws an exception intermittently when trying to invoke a web method via web reference. The web reference is the old school ASP.NET web services with the .asmx file extension.

The main web application and the web service are both on IIS 7.5 / Windows 2008 SP1. In IIS both apps are on the same website but in different application pools.

The exception states "An existing connection was forcibly closed by the remote host". This error is strange because it doesn't throw the exception the first several times when the web method is called. But when the error is thrown, it will then continue to be thrown on every following instance. Restarting the app pool in IIS fixes the error.

The data being transmitted is minimal so I don't think it is related the size of the data.

Recently we installed an F5 device that acts as a reverse proxy. The web service is now running behind this device. We did this in order to move the application to a DMZ (Demilitarized Zone). This could be the cause to this issue but if it is I am unsure how to properly configure it.

Here is my code:

_webService = New BWebService.BWebService()
_webService.Url = EnvironmentSettingsLocator.Settings.BWebServiceWsdl
If Not _webService.IsExistingUser(userId) Then 
' Do Something
end if

Here is the exception:

The underlying connection was closed: An unexpected error occurred on a receive.

    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 Apex3Web.BIRVWebService.BIRVWebService.IsExistingUser(Int32 userCode) in C:\Users\Ryan.DeFour.ctr\Documents\Work\TFS Source Code 2010\APEX4CMMI\APEXDevelopment\Apex3Web\Apex3Web\Web References\BIRVWebService\Reference.vb:line 501
   at Apex3Web.ManageExaminee.GridViewExaminees_RowDataBound(Object sender, GridViewRowEventArgs e) in C:\Users\Ryan.DeFour.ctr\Documents\Work\TFS Source Code 2010\APEX4CMMI\APEXDevelopment\Apex3Web\Apex3Web\Forms\Examiner\ManageExaminee.aspx.vb:line 651
   at System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs e)
   at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
   at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
   at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
   at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
   at System.Web.UI.WebControls.GridView.DataBind()
   at Apex3Web.ManageExaminee.FindCommand_Click(Object sender, EventArgs e) in C:\Users\Ryan.DeFour.ctr\Documents\Work\TFS Source Code 2010\APEX4CMMI\APEXDevelopment\Apex3Web\Apex3Web\Forms\Examiner\ManageExaminee.aspx.vb:line 539
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.TlsStream.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)

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)
Ryan
  • 11
  • 3
  • Does the remote host have a timeout setting that is not set to what you need it to be? – RandomUs1r Jul 29 '14 at 17:09
  • well... something's got to host the end point right? That something most likely has a timeout setting. Basically your error means that the remote host closed the connection before your web app is done causing your web app to error. This could be due to timeout on the remote host. Another reason this could happen is an unstable connection. Try doing a ping -t on the remote host & see if you get any packet loss. Do you have access to the remote host by chance? – RandomUs1r Jul 29 '14 at 17:22
  • I found this in the web.config on the remote host: – Ryan Jul 29 '14 at 17:25
  • Yes I can get access to this server. Would an exception be thrown on the remote host if a request was timed out? – Ryan Jul 29 '14 at 18:50
  • Not necessarily an exception, but you should be able to see the closed connections in windows event log under application. Also, if you have access IIS on that server should have a timeout property, try raising that. Take a look at these two threads for other things to try: http://stackoverflow.com/questions/2862817/an-existing-connection-was-forcibly-closed-by-the-remote-host http://stackoverflow.com/questions/9117628/error-consuming-web-service-an-existing-connection-was-forcibly-closed – RandomUs1r Jul 30 '14 at 20:54
  • We recently installed a new F5 device which acts as a reverse proxy. We think this is our problem. When invoking a WCF service from a client application, I'm also getting an error. This error states "An error occurred while receiving the HTTP response to https://.../CustomHttps. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details." Do you think changing any binding settings could resolve this issue? – Ryan Aug 04 '14 at 14:17
  • I would think that F5 would be helpful if you asked them about it. – Andrew Morton Aug 05 '14 at 14:16

1 Answers1

0

The source of our issue was the newly installed F5 BigIP reverse proxy device which had SSL load balancing capabilities. The application threw exceptions during invocations to SOAP-based services (both WCF and ASMX). While speaking to an F5 representative, we were able to properly configure the device so requests would simply pass through the device instead of using the load balancing functions. This was probably not the most elegant solution, but in interest of time this is what we had to do to make it happen.

Ryan
  • 11
  • 3