locked
maxBytesPerRead ,....strange. RRS feed

  • Question

  • Hello,

    Env : VS Studio 2010 / .NET 4

    I am currently using WCF with streamed transfer mode.

    maxBytesPerRead configuration value is working?

    I changed this setting in server & client both to see how many bytes will be actually read..

    When MessageEncoding is Mtom, actual read bytes seems always 4096.

    When MessageEncoding is Text, actual read bytes seems always 1536

    It really doesn't matter what value you set for maxBytesPerRead in the configuration...My server & client is even on same machine...

    Any idea?

    Thursday, February 20, 2014 7:48 PM

Answers

  • TCP maximum datagram is approximately 1500 bytes (can vary by a couple of bytes with implimention so everybody says approximately).  The transport layer for html uses TCP.  When TCP messages are greater than 1500 bytes the messages are broken into multiple datagrams by the sender network driver.

    As the 1500 bytes datagrams are forwarded from your PC network card they are not combined and you must write your code to handle 1500 block sizes.  Youe real issue is how to determine with a stream when you actually finish reading all the data.  I don't like Microsoft implimentation of network streams.  Microsoft expects after all the data is sent the sender will close the connection so you must handle the connection close event.  A problem occurs with this implimentation because you have a race condition where the connection could be closed before all the data gets received.  I have never seen a good solution from microsoft about methods to solve this issue.


    jdweng

    Friday, February 21, 2014 9:30 AM