An existing connection was forcibly closed by the remote host

Discussion in 'ASP .Net Web Services' started by Wil Peck, Jan 16, 2008.

  1. Wil Peck

    Wil Peck Guest

    So here is the scenario...

    I have a console application executing a Web Method on my WSDL generated
    System.Web.Protocols.SoapHttpClientProtocol instance using HTTP over a VPN.
    For some reason requests that are larger than 1024 bytes are timing out and
    the stack trace ends up being something like the above. I can't find where
    there are any maxRequestLength (that applies to requests a client makes to a
    web service) that can be adjusted to accommodate for larger requests.

    Below is an snippet of the stack trace minus any proprietary info.

    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)

    I have done a trace on the System.Net.Sockets which seems to show that the
    request wasn't really completed by the SoapHttpClientProtocol instance.
    Please note that this was working fine until we applied patches to our Win2k
    machine and then after the patches were applied it stopped working. I have
    been able to get the service to work on WinXP fully patched, but not on
    Windows Server 2k3 or Win Server 2k.

    My hunch is the request is never fully written to the host of the web
    service and the web service finally decides to close the connection because
    it received an incomplete message. In an attempt to give the request more
    time to complete I have increased the WebClientProtocol.Timeout to 2 minutes
    without any success. If anyone has any other ideas on this it would be
    greatly appreciated.

    Thanks - Wil
     
    Wil Peck, Jan 16, 2008
    #1
    1. Advertising

  2. Wil Peck

    Wil Peck Guest

    I finally figured out how to address this specific issue. Within my web
    service proxy class I overrode the GetWebRequest(uri) method and modified it
    as shown below.

    protected override System.Net.WebRequest GetWebRequest(Uri uri)
    {
    HttpWebRequest request = base.GetWebRequest(uri) as
    HttpWebRequest;
    request.SendChunked = true;
    return request;
    }

    What I still haven't taken the time to figure out is why this behavior
    changed after we applied windows service packs to our machine. If the size
    of the request message I was using is greater than the size of the packets
    the host could receive and the host is configured receive chunked messages
    then I guess I can assume (I hate assuming things) when we sent a message
    larger than the packet size without sending it chunked their server
    terminated the session because it was waiting for another TCP message???

    Hard to tell without being able to easily work with the web service host
    directly. At any rate I hope this helps anyone else who encounters the same
    problem.

    "Wil Peck" <> wrote in message
    news:...
    > So here is the scenario...
    >
    > I have a console application executing a Web Method on my WSDL generated
    > System.Web.Protocols.SoapHttpClientProtocol instance using HTTP over a
    > VPN. For some reason requests that are larger than 1024 bytes are timing
    > out and the stack trace ends up being something like the above. I can't
    > find where there are any maxRequestLength (that applies to requests a
    > client makes to a web service) that can be adjusted to accommodate for
    > larger requests.
    >
    > Below is an snippet of the stack trace minus any proprietary info.
    >
    > 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)
    >
    > I have done a trace on the System.Net.Sockets which seems to show that the
    > request wasn't really completed by the SoapHttpClientProtocol instance.
    > Please note that this was working fine until we applied patches to our
    > Win2k machine and then after the patches were applied it stopped working.
    > I have been able to get the service to work on WinXP fully patched, but
    > not on Windows Server 2k3 or Win Server 2k.
    >
    > My hunch is the request is never fully written to the host of the web
    > service and the web service finally decides to close the connection
    > because it received an incomplete message. In an attempt to give the
    > request more time to complete I have increased the
    > WebClientProtocol.Timeout to 2 minutes without any success. If anyone has
    > any other ideas on this it would be greatly appreciated.
    >
    > Thanks - Wil
     
    Wil Peck, Jan 17, 2008
    #2
    1. Advertising

  3. Wil Peck

    Wil Peck Guest

    I finally figured out how to address this specific issue. Within my web
    service proxy class I overrode the GetWebRequest(uri) method and modified it
    as shown below.

    protected override System.Net.WebRequest GetWebRequest(Uri uri)
    {
    HttpWebRequest request = base.GetWebRequest(uri) as
    HttpWebRequest;
    request.SendChunked = true;
    return request;
    }

    What I still haven't taken the time to figure out is why this behavior
    changed after we applied windows service packs to our machine. If the size
    of the request message I was using is greater than the size of the packets
    the host could receive and the host is configured receive chunked messages
    then I guess I can assume (I hate assuming things) when we sent a message
    larger than the packet size without sending it chunked their server
    terminated the session because it was waiting for another TCP message???

    Hard to tell without being able to easily work with the web service host
    directly. At any rate I hope this helps anyone else who encounters the same
    problem.


    "Wil Peck" <> wrote in message
    news:...
    > So here is the scenario...
    >
    > I have a console application executing a Web Method on my WSDL generated
    > System.Web.Protocols.SoapHttpClientProtocol instance using HTTP over a
    > VPN. For some reason requests that are larger than 1024 bytes are timing
    > out and the stack trace ends up being something like the above. I can't
    > find where there are any maxRequestLength (that applies to requests a
    > client makes to a web service) that can be adjusted to accommodate for
    > larger requests.
    >
    > Below is an snippet of the stack trace minus any proprietary info.
    >
    > 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)
    >
    > I have done a trace on the System.Net.Sockets which seems to show that the
    > request wasn't really completed by the SoapHttpClientProtocol instance.
    > Please note that this was working fine until we applied patches to our
    > Win2k machine and then after the patches were applied it stopped working.
    > I have been able to get the service to work on WinXP fully patched, but
    > not on Windows Server 2k3 or Win Server 2k.
    >
    > My hunch is the request is never fully written to the host of the web
    > service and the web service finally decides to close the connection
    > because it received an incomplete message. In an attempt to give the
    > request more time to complete I have increased the
    > WebClientProtocol.Timeout to 2 minutes without any success. If anyone has
    > any other ideas on this it would be greatly appreciated.
    >
    > Thanks - Wil
     
    Wil Peck, Jan 17, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    11,622
    Esmond Pitt
    Mar 3, 2005
  2. iKiLL
    Replies:
    0
    Views:
    499
    iKiLL
    Dec 20, 2006
  3. Anbu
    Replies:
    4
    Views:
    571
    Juan T. Llibre
    Mar 13, 2007
  4. Artur
    Replies:
    1
    Views:
    601
  5. iKiLL
    Replies:
    0
    Views:
    662
    iKiLL
    Dec 20, 2006
Loading...

Share This Page