WSAEINPROGRESS

 

When i use the method getRequestStream() of an object HttpWebRequest, and try
to write to this stream i got a socket exception.

The errorcode is 10036, WSAEINPROGRESS.

            Dim postBytes() As Byte
            Dim asciiEncode As Encoding = New ASCIIEncoding
            postBytes = asciiEncode.GetBytes(Me.mQuery)
            httpReq.ContentType = "application/x-www-form-urlencoded"
            httpReq.ContentLength = postBytes.Length
            Dim newStream As Stream = httpReq.GetRequestStream()
            Try
                newStream.Write(postBytes, 0, postBytes.Length)
            Catch ex As SocketException
                MsgBox(ex.ErrorCode, MsgBoxStyle.OKOnly, "test")
            End Try
            newStream.Close()

hints

Thanks



Answer this question

WSAEINPROGRESS

  • Andy K Smith

     

     POST of 69 bytes.

    Just alphanumeric characters.


  • Jonas Bergman

    I believe I have run into the same problem; I can not post data to an https site using any NETCF V1, including SP3. Using NETCF V2 SP2, it works. I would prefer to continue to use NETCF V1, as existing devices have this pre-installed.

    Similar to the original post, I am receiving a SocketException (A blocking operation is currently executing) when the strmPost.write method is called.

    I have noticed the following:

    1. It often (not always) works on the first post, but by the second post it will fail. I believe that I am closing all resources appropriately. I have tried a number of different options regarding closing these resources; they all have the same issue.

    2. If I place a breakpoint on the write method, it always succeeds (even if the current execution has previously failed). Placing a strmPost.Flush() or Thread.Sleep in front the write does not make the error go away, though.

    3. When the exception is thrown, there is typically another thread executing that I did not create; I believe that the https library automatically creates it to perform the SSL layer. I believe it is this thread that causes blocking exception to occur, it looks like it is still performing the ssl handshaking. A callstack of this thread is below.

    I believe that it is being caused the write operation not cooperating with the ssl handshaking; I think it is trying to send it's bytes down the raw socket stream before the handshaking is complete. Below is the posting code; I have a simple test solution that fires this if it is useful.

    Are there any options for me other than to update all of my user's devices to CF 2.0 From what I can tell, https posting doesn't work under CF 1.0. That doesn't sound right, so I suspect that I am doing something wrong.

    Thank you.

    Callstack for thread automatically created by HTTPS library; immediately after exception is thrown:

    mscorlib.dll!System.String.String(char[] value = {Length=8}, int startIndex = 0, int length = 8)
    mscorlib.dll!System.Globalization.TextInfo.ChangeCaseString(bool isToUpper = false, string str = "HTTP/1.1") + 0x42 bytes
    mscorlib.dll!System.Globalization.TextInfo.ToLower(string str = "HTTP/1.1") + 0x8 bytes
    mscorlib.dll!System.String.ToLower(System.Globalization.CultureInfo culture = {System.Globalization.CultureInfo}) + 0x15 bytes
    System.dll!System.Net.HttpWebRequest.parseResponse(System.Net.HttpWebRequest request = {System.Net.HttpWebRequest}, System.Net.Connection connection = {System.Net.Connection}, bool defaultKeepAlive = true) + 0x6e bytes
    System.dll!System.Net.HttpWebRequest.startReceiving(System.Net.Connection connection = {System.Net.Connection}) + 0x82 bytes
    System.dll!System.Net.Connection.startReceiving(System.Object ignored = <undefined value>) + 0x29 bytes
    mscorlib.dll!System.Threading.ThreadPool.WorkItem.doWork(System.Object o = <undefined value>) + 0x36 bytes
    mscorlib.dll!System.Threading.Timer.ring() + 0x59 bytes

    Posting Code:

    string strPost = "Test";
    byte[] yABuffer = Encoding.ASCII.GetBytes(strPost);

    HttpWebRequest request = null;
    Stream strmPost = null;
    HttpWebResponse response = null;
    Stream strmResponse = null;
    StreamReader reader = null;
    string strResponse;

    try {
    // Build request
    request = (HttpWebRequest)WebRequest.Create("https://dev.sigmacare.net/hh/Listener.aspx"); // Note: I have tried a few sites, with different ssl certs; they all fail
    //request.KeepAlive = false; // Note: makes no difference
    request.Method = "POST";
    request.ContentLength = yABuffer.Length;

    // Post data
    strmPost = request.GetRequestStream();
    strmPost.Write(yABuffer, 0, yABuffer.Length); // This is the line that causes the exception
    strmPost.Close();
    strmPost = null;

    // Get response
    response = (HttpWebResponse) request.GetResponse();
    strmResponse = response.GetResponseStream();
    reader = new StreamReader(strmResponse);
    strResponse = reader.ReadToEnd();
    reader.Close();
    reader = null;
    strmResponse.Close();
    strmResponse = null;

    this.textBox1.Text = strResponse;
    } catch (Exception ex) {
    this.textBox1.Text = ex.Message;
    } finally {
    if (strmPost != null) {
    try { strmPost.Close(); } catch (Exception) { }
    strmPost = null;
    }
    if (strmResponse != null) {
    try { strmResponse.Close(); } catch (Exception) { }
    strmResponse = null;
    }
    if (reader != null) {
    try { reader.Close(); } catch (Exception) { }
    reader = null;
    }
    }


  • BobMaupin

    Is this the only thread in the application.. Or do you have another thread trying to access the same HttpWebRequest..

    From the MSDN

    WinSock only allows a single blocking operation to be outstanding per task (or thread), and if you make any other function call (whether or not it references that or any other socket) the function fails with the WSAEINPROGRESS error. It means that there is a blocking operation outstanding. It is also possible that WinSock might return this error after an application calls connect() a second time on a non-blocking socket while the connection is pending (after the first connection failed with WSAEWOULDBLOCK). can you paste the code starting from the creation of httpwebrequest..


  • ChicagoDave

    What is the length of your POST

  • Primo109

    1. Which version of framework are you using. 1.1 or 2.0..
    A:.NET Framework 1.1 without service Pack

    2. Is this on Compact Framework
    A:Yes. Windows CE.net 4.2

    3. What was the verb used for HttpWebRequest. Is it possible to get a small repro of the problem right from the creation of the webrequest.
    A:POST. I just followed the MSDN samples of posting data to the server using the HttpWebRequest class. I created a windows form to configure the host, path e query data and to watch the response.

    The problem is in the newStream.Write method. If I comment out this
    line it will work perfect. The response will be sent.

                Dim postBytes() As Byte
                Dim asciiEncode As Encoding = New ASCIIEncoding
                postBytes = asciiEncode.GetBytes(Me.mQuery)
                httpReq.ContentType = "application/x-www-form-urlencoded"
                httpReq.ContentLength = Me.mQuery.Length
                Dim newStream As Stream = httpReq.GetRequestStream()
                Try
                    If (newStream.CanWrite()) Then
                        newStream.Write(postBytes, 0, postBytes.Length)
                    End If
                Catch ex As SocketException
                    MsgBox(ex.ErrorCode, MsgBoxStyle.OKOnly, "teste")
                End Try
                MsgBox("teste", MsgBoxStyle.OKOnly, "teste")
                newStream.Close()


    4. Does this occur when you hit other sites.. Can you repro it with another site which i can hit too
    A:I just discovered that this happens when i use secure connection (https). Otherwise there's no problem.


  • Chippen

    That is bad..

    A couple of questions to reproduce this..

    1. Which version of framework are you using. 1.1 or 2.0..

    2. Is this on Compact Framework

    3. What was the verb used for HttpWebRequest. Is it possible to get a small repro of the problem right from the creation of the webrequest..

    4. Does this occur when you hit other sites.. Can you repro it with another site which i can hit too

    Thanks

    Malar

     

     


  • Balasaheb

    Hi,

    What is the build number of NETCF that you used You can get the NETCF build number of the device by running cgacutil.exe under the windows directory.

    Thanks,

    Anthony Wong [MSFT]


  • Chaz Clover

    I have a single process/thread executing ... 

    I already read this MSDN documentation but it didn't help me to understand what is happening. Mainly because i'm not using winsock... I'm trying to use a higher level api and don't know how Microsoft used Winsock inside it. The point is, my application is a single process/thread and it doesn't work . I suspect that the "Supported by the .NET Compact Framework" clause is not for real (or the documentation lacks information). I've been working on this since early in the morning, tried callbacks, change properties, etc...

    Thanks anyway

     


  • Jaypee

    Hi Hiparco,

    Could you try the latest service pack, i.e. NETCF V1 SP3, or NETCF V2 There are issues found in the V1 RTM release that have been fixed in these later releases.

    Cheers,

    Anthony Wong [MSFT]


  • Luke Waters

    Microsoft (R) .NET Compact Framework [1.0.2268.00]

    Thanks


  • MartinPar&amp;#233;

    Moving this thread to the compact framework forum as they will be better able to help you out.

  • Metall

    Other problem that is ocurring (sometimes)

    WSASYSCALLFAILURE

    10107

    A system call that should never fail has failed.

     lol


  • WSAEINPROGRESS