Stange Behavior with Streaming TCP connection RRS feed

  • Question

  • We have a web service for performing file transfers. For small files we just send the file within the response.  This works fine and generates no errors.  For large files we return a stream.  The client takes the stream and creates a file, closes the stream and closed the channel.  None of this generates an error.  We are able to make multiple calls intermixing a "regular" response object and streamed responses and all work as expected.

    When we have finish totally and the client code exits, We receive an error on the server.  Keep in mind that all streams and channels have been correctly closed and disposed.  When the application exits we get the trance below.  Its as if an Async channel has been created under the hood and when the application closes that channel results in the error.  We have no explicit Async code in our application.  It's as if .NET creates the connection for its use on the client and leaves it dangling. Since our code didn't create the channel I'm not sure how to get a handle on it so we can close it as part of the application shutdown.  We are using TCP with certificates for out communication.  Is it possible that an Async channel is established and part of the Security negotiation or something similar?  When the client exits it destroys the channel creating the server side error.

    The server method: public Stream GetSolutionsDocumentStream(GetDocumentRequest request)

    The client code: (note we broke this apart to discrete steps for debugging)

                    var ws = new FileTransferServiceClient();
                    var req = new GetDocumentRequest{FileLocation = @"\documents\Test\test.txt"};
                    var fileStream = new FileStream(@"c:\test\out1.txt", FileMode.Create, FileAccess.Write, FileShare.None, 4096, true);

    The trace off server:

    <E2ETraceEvent xmlns="">
      <System xmlns="">
        <SubType Name="Error">0</SubType>
        <TimeCreated SystemTime="2015-11-30T13:19:02.0705535Z" />
        <Source Name="System.ServiceModel" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessName="Solutions.Enterprise.ServiceHost" ProcessID="2064" ThreadID="14" />
        <Channel />
            <TraceRecord xmlns="" Severity="Error">
              <Description>Throwing an exception.</Description>
                <ExceptionType>System.Net.Sockets.SocketException, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
                <Message>An existing connection was forcibly closed by the remote host</Message>
                  at System.ServiceModel.Channels.SocketConnection.HandleReceiveAsyncCompleted()
                  at System.ServiceModel.Channels.SocketConnection.OnReceiveAsync(Object sender, SocketAsyncEventArgs eventArgs)
                  at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
                  at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
                  at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
                <ExceptionString>System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host</ExceptionString>

    • Moved by Fred Bao Tuesday, December 1, 2015 1:48 AM web service related
    • Moved by Dave PatrickMVP Tuesday, December 1, 2015 2:54 PM
    Monday, November 30, 2015 4:13 PM

All replies

  • Hello John B,

    From your description, this issue is related with the web service, I recommend you ask it on the web service forum:

    The current forum is for WCF Data Service questions.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 1, 2015 1:48 AM
  • This is a shelf hosted data service making use of WCF.  I love all the moderators who are so concerned about the purity of their forums that they lose site of the reason they exist, to help the users.  We are using WCF to supply data to our Winform applications from a back end database.  Part of our offline model includes replication (synchronization) of the main database with the user's laptop.  This includes copying file images.

    Thanks for the assistance

    Tuesday, December 1, 2015 11:19 AM
  • Hi John B,

    According to this case, may be you can try set this node in your web.config file.

    Like below:

        <behavior name="AsyncStreaming">
          <dispatcherSynchronization asynchronousSendEnabled="false" />

    As you said asynchronous channel has been created under the hood and when the

    application closes that channel results in the error. So, we can try set

    asynchronousSendEnabled="false". Then we need to tracing continue if there have the

    error still. Then find the root error.

    For more information, please refer to the following link:

    1.WCF TCP-based File Server

    Best Regards,


    Wednesday, December 2, 2015 7:40 AM