none
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

    Question

  • While Calling a wcfservice I am getting following error. My method return 16,000 records. When I forcefully made this method to return 10 records, it worked fine. So I think, when web service returns large amount of data, the connection gets closed by some sort of resource manager in .net framework. Please look below error, if you have any solution for that please provide me.

    Thanks in advanced

    Server Error in '/' Application.

    An existing connection was forcibly closed by the remote host

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

    Source Error:

    Line 2701:        
    Line 2702: public System.Collections.Generic.List<AtlasLocal.APIReferences.Listing> GetAllListingBySite(string Alias) {
    Line 2703: return base.Channel.GetAllListingBySite(Alias);
    Line 2704: }
    Line 2705:

    Source File: D:\Project\JCTProjects\SalonSpa1\AtlasLocal\Service References\APIReferences\Reference.cs    Line: 2703

     Message="An error occurred while receiving the HTTP response to http://api.salonspa.com/Services.svc. 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."
      Source="mscorlib"

    Stack Trace:

    [SocketException (0x2746): An existing connection was forcibly closed by the remote host]
    System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +73
    System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +131

    [IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]
    System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +294
    System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) +26
    System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) +297

    [WebException: The underlying connection was closed: An unexpected error occurred on a receive.]
    System.Net.HttpWebRequest.GetResponse() +5313085
    System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +54

    [CommunicationException: An error occurred while receiving the HTTP response to http://api.salonspa.com/Services.svc. 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.]
    System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +7594687
    System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +275
    AtlasLocal.APIReferences.IServices.GetAllListingBySite(String Alias) +0
    AtlasLocal.APIReferences.ServicesClient.GetAllListingBySite(String Alias) in D:\Project\JCTProjects\SalonSpa1\AtlasLocal\Service References\APIReferences\Reference.cs:2703
    AtlasLocal.APIServices.Services.SerachListing(String Alias) in D:\Project\JCTProjects\SalonSpa1\AtlasLocal\APIServices\Services.cs:67
    AtlasLocal.Utils.Base.get_SiteAlias() in D:\Project\JCTProjects\SalonSpa1\AtlasLocal\Utils\Base.cs:178
    AtlasLocal.Utils.AtlasLocalPage.get_PageTitle() in D:\Project\JCTProjects\SalonSpa1\AtlasLocal\Utils\Base.cs:621
    ASP.default_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in d:\Project\JCTProjects\SalonSpa1\AtlasLocal\Default.aspx:10
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
    System.Web.UI.Page.Render(HtmlTextWriter writer) +29
    System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
    AtlasLocal.Default.RenderControl(HtmlTextWriter writer) in D:\Project\JCTProjects\SalonSpa1\AtlasLocal\Default.aspx.cs:40
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266


    Version Information:  Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3072
    Saturday, August 15, 2009 11:57 AM

Answers

  • Hi,

    This issue is obviously relate to message size, threre are two options you could try here:

    First of all you can try to increase the corespond binding attribute elements both on client and server sides such as:
     <binding name="BasicHttpBinding_IStudentManagement" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferSize="1000000000" maxBufferPoolSize="1000000000" maxReceivedMessageSize="1000000000"
                        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                        useDefaultWebProxy="true">
                        <readerQuotas maxDepth="32" maxStringContentLength="1000000000" maxArrayLength="1000000000"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />

    If it's still not working that means your data is too large to process by buffered transfer-mode, then you could try to use streamed transfer-mode to process the data from server to client. See this refference website for how to enable streamed transfer-mode:
    http://msdn.microsoft.com/en-us/library/ms789010.aspx

    Thanks
    Binze
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bin-ze Zhao Friday, August 21, 2009 4:02 AM
    Wednesday, August 19, 2009 4:07 AM
  • Although you receive the exception on the client side, notice that the exception is telling you that the connection was "forcibly closed by the remote host". The "remote host" is the server, so you need to find out why it closed the connection. In order to do that, you need to look in the server event log, or turn on tracing.

    Just like the experts here told you to do.

    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    • Marked as answer by Bin-ze Zhao Wednesday, August 19, 2009 3:52 AM
    • Unmarked as answer by Bin-ze Zhao Wednesday, August 19, 2009 3:59 AM
    • Marked as answer by Bin-ze Zhao Friday, August 21, 2009 4:02 AM
    Sunday, August 16, 2009 2:24 AM
    Moderator

All replies

  • Turn on tracing at the service side, you should get some more info on the error.

    Regards,
    Stipe-Ivan
    Saturday, August 15, 2009 12:08 PM
  • Thanks

    its not error from service side.

    i found below error.

    An error occurred while receiving the HTTP response to http://api.salonspa.com/Services.svc. 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.


    One More thing,
    My method return 13,000 records. When I forcefully made this method to return 2000 records, it worked fine.
    but i increased the size of return record its give this error.

    help me
    Saturday, August 15, 2009 12:38 PM
  • Although you receive the exception on the client side, notice that the exception is telling you that the connection was "forcibly closed by the remote host". The "remote host" is the server, so you need to find out why it closed the connection. In order to do that, you need to look in the server event log, or turn on tracing.

    Just like the experts here told you to do.

    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    • Marked as answer by Bin-ze Zhao Wednesday, August 19, 2009 3:52 AM
    • Unmarked as answer by Bin-ze Zhao Wednesday, August 19, 2009 3:59 AM
    • Marked as answer by Bin-ze Zhao Friday, August 21, 2009 4:02 AM
    Sunday, August 16, 2009 2:24 AM
    Moderator
  • Hi,

    This issue is obviously relate to message size, threre are two options you could try here:

    First of all you can try to increase the corespond binding attribute elements both on client and server sides such as:
     <binding name="BasicHttpBinding_IStudentManagement" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferSize="1000000000" maxBufferPoolSize="1000000000" maxReceivedMessageSize="1000000000"
                        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                        useDefaultWebProxy="true">
                        <readerQuotas maxDepth="32" maxStringContentLength="1000000000" maxArrayLength="1000000000"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />

    If it's still not working that means your data is too large to process by buffered transfer-mode, then you could try to use streamed transfer-mode to process the data from server to client. See this refference website for how to enable streamed transfer-mode:
    http://msdn.microsoft.com/en-us/library/ms789010.aspx

    Thanks
    Binze
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bin-ze Zhao Friday, August 21, 2009 4:02 AM
    Wednesday, August 19, 2009 4:07 AM