WCF Time out Error RRS feed

  • Question

  • Hi,

    We have an application that has a WCF service and many clients connect to this service to download files. Files are downloaded in chunks (4kb) and transfer mode is ‘streamedResponse’. The binding configured is ‘BasicHttpBinding‘. When multiple clients try to download huge files simultaneously the following errors are thrown,

    1. An error occurred while receiving the HTTP response to (https://). 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.

    Server stack trace:

    at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)

    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

    at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)

    at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)

    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    2. 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 '01:00:00'.

    Stack Trace: at System.ServiceModel.Channels.HttpInput.WebResponseHttpInput.WebResponseInputStream.Read(Byte[] buffer, Int32 offset, Int32 count)

    at System.ServiceModel.Channels.MaxMessageSizeStream.Read(Byte[] buffer, Int32 offset, Int32 count)

    at System.ServiceModel.Channels.DrainOnCloseStream.Close()

    at System.Xml.BufferedReadStream.Close()

    at System.Xml.XmlMtomReader.Close()

    at System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream.Close()

    at System.IO.Stream.Dispose()


    3. The socket transfer timed out after 01:00:00. You have exceeded the timeout set on your binding. The time allotted to this operation may have been a portion of a longer timeout.

    We have tried out the below possible solutions but we are still facing this error,

    1. We Increased the sendTimeout and receiveTimeout
    2. The value for MaxBufferSize, MaxBufferPoolSize, MaxReceivedMessageSize is set to higher value.

    PFB the code snippet for file download,

    using (FileStream writeStream = new System.IO.FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write))
                            _Logger.WriteLine("Started downloading the Package");
                            const int chunkSize = 4096;
                            int currentPosition = 0;
                            long totalSizeCount = 0;
                            bool isLastChunk = false;
                            byte[] buffer = new byte[chunkSize];
                                int bytesRead = inputStream.Read(buffer, 0, chunkSize);
                                if (bytesRead == 0) break;
                                totalSizeCount += bytesRead;
                                isLastChunk = ((length - totalSizeCount <= 0) ? true : false);
                                currentPosition = currentPosition + bytesRead;
                                if (currentPosition == chunkSize || isLastChunk)
                                    writeStream.Write(buffer, 0, currentPosition);
                                    currentPosition = 0;
                            while (true);

    • Edited by Sumantha Tuesday, September 10, 2013 11:28 AM
    Tuesday, September 10, 2013 11:26 AM


  • Hi,

    It will be better if you post your web configure file here.

    In addition to those message size and serialization reader related quota settings, you might also need to enlarge the "maxRequestLength" attribute of the <httpRuntime> config element of ASP.NET web application.

    #maxRequestLength attribute of httpRuntime Element (ASP.NET Settings Schema) .

    And the following configuration taken from MSDN can be applied to enable tracing on your wcf service to find the cause of those error.

          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true" >
                 <add name="xml"/>
          <source name="System.ServiceModel.MessageLogging">
                <add name="xml"/>
          <source name="myUserTraceSource"
                  switchValue="Information, ActivityTracing">
                <add name="xml"/>
            <add name="xml"
                 initializeData="Error.svclog" />

    Best Regards,
    Amy Peng

    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, September 11, 2013 7:54 AM