locked
System.IO.IOException: Unable to read data from the transport connection

    Question

  •  

    Hello,

     

    I have an xml webservice calling another xml web service and occasionally i get the following error - any ideas why?Does this happen when the request is made or when reading the response? Also how i can prevent it from happening? Thanks

     

    System.IO.IOException: Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall. ---> System.Net.Sockets.SocketException: A blocking operation was interrupted by a call to WSACancelBlockingCall
       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.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
       at System.IO.StreamReader.ReadBuffer(Char[] userBuffer, Int32 userOffset, Int32 desiredChars, Boolean readToUserBuffer)
       at System.IO.StreamReader.Read(Char[] buffer, Int32 index, Int32 count)
       at System.Xml.XmlTextReaderImpl.ReadData()
       at System.Xml.XmlTextReaderImpl.InitTextReaderInput(String baseUriStr, TextReader input)
       at System.Xml.XmlTextReaderImpl..ctor(String url, TextReader input, XmlNameTable nt)
       at System.Xml.XmlTextReader..ctor(TextReader input)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.GetReaderForMessage(SoapClientMessage message, Int32 bufferSize)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

     

     

    Wednesday, December 05, 2007 5:58 PM

Answers

  • It might be that the call to your second webservice is timing out or before it finishes reading your parent webservice is timing out.

     

    Try increasing the timeout for the call to the second webservice and also make sure your parent webservice has higher timeout than the call to second web service.

    Friday, December 07, 2007 1:17 AM
  • Just for information: This is a repro that would simulate a simillar scenario and causes simillar exception trace.

     

    class Program

    {

    static void Main(string[] args)

    {

    //Start the listening on a Background worker

    BackgroundWorker worker = new BackgroundWorker();

    worker.DoWork += new DoWorkEventHandler(StartListening);

    worker.RunWorkerAsync();

    //Connect to the service

    TcpClient client = new TcpClient("localhost", 8989);

    client.ReceiveTimeout = 200;

    // This thread will try to close the client connection, before the ReadByte completes.

    new Thread(new ParameterizedThreadStart(CloseClientConnection)).Start(client);

    client.GetStream().ReadByte();

    }

     

    static void CloseClientConnection(object sender)

    {

    //Give some time for the Read to start

    Thread.Sleep(50);

    ((TcpClient)sender).Close();

    }

    static void StartListening(object sender, DoWorkEventArgs e)

    {

    TcpListener listener = new TcpListener(8989);

    listener.Start();

    listener.AcceptTcpClient();

    Thread.Sleep(1000);

    listener.Stop();

    }

    }

    Friday, December 07, 2007 1:52 AM

All replies

  • It might be that the call to your second webservice is timing out or before it finishes reading your parent webservice is timing out.

     

    Try increasing the timeout for the call to the second webservice and also make sure your parent webservice has higher timeout than the call to second web service.

    Friday, December 07, 2007 1:17 AM
  • Just for information: This is a repro that would simulate a simillar scenario and causes simillar exception trace.

     

    class Program

    {

    static void Main(string[] args)

    {

    //Start the listening on a Background worker

    BackgroundWorker worker = new BackgroundWorker();

    worker.DoWork += new DoWorkEventHandler(StartListening);

    worker.RunWorkerAsync();

    //Connect to the service

    TcpClient client = new TcpClient("localhost", 8989);

    client.ReceiveTimeout = 200;

    // This thread will try to close the client connection, before the ReadByte completes.

    new Thread(new ParameterizedThreadStart(CloseClientConnection)).Start(client);

    client.GetStream().ReadByte();

    }

     

    static void CloseClientConnection(object sender)

    {

    //Give some time for the Read to start

    Thread.Sleep(50);

    ((TcpClient)sender).Close();

    }

    static void StartListening(object sender, DoWorkEventArgs e)

    {

    TcpListener listener = new TcpListener(8989);

    listener.Start();

    listener.AcceptTcpClient();

    Thread.Sleep(1000);

    listener.Stop();

    }

    }

    Friday, December 07, 2007 1:52 AM
  • I know I should open my own topic, but I don't see the point in that, because everything to explain is here, and the code is similiar, the idea is the same.

    My app also raises that exception when the thread is reading the bytes and I press CAncel button, which will abort the thread. Sometimes it raises the exception, but sometimes doesn't.

    The code is similar to the above one. There's a method to download using a different thread and there's a cancel button which will abort the download, that is, abort the thread.

    Ravichandhiran <abbr class="affil"> showed the </abbr> scenario and mine it's pretty much like that, but he didn't say what to do to overcome this issue.

    He said about increase the timeout, but it does not work. I don't have one webservice calling another, I have only one.


    So, what do to?


    Get a life. Go party!
    Friday, August 27, 2010 8:54 PM
  • Start a new thread.

     

    This one is from three years ago and there was no real answer so how do you know yours is the same?


    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
    Sunday, August 29, 2010 2:19 AM