Hi all,<div><br></div><div>My project uses WCF to perform remoting communications between a server and a client.</div><div>Sometimes I have to transfer 'large' data (large meaning here "more than the default max value").</div>

<div><br></div>
<div>So to get transferts to work, I had to declare my binding with the following parameters:</div><div><div><span style="white-space:pre-wrap">        </span>var binding = new NetTcpBinding ();</div><div><span style="white-space:pre-wrap">      </span>binding.Security.Mode = SecurityMode.None;</div>


<div><span style="white-space:pre-wrap">  </span>binding.OpenTimeout = new TimeSpan(1,0,0);</div><div><span style="white-space:pre-wrap">       </span>binding.SendTimeout = new TimeSpan(1,0,0);</div>
<div><span style="white-space:pre-wrap">  </span>binding.CloseTimeout = new TimeSpan(1,0,0);</div><div><span style="white-space:pre-wrap">      </span>binding.MaxReceivedMessageSize = 1000000000;</div>
<div><span style="white-space:pre-wrap">  </span>binding.MaxBufferPoolSize = 100000000;</div><div><span style="white-space:pre-wrap">   </span>var address = new EndpointAddress ("net.tcp://"+serverIP+":"+serverPort+"/");</div>


</div><div><div><span style="white-space:pre-wrap">   </span>IRemoteOperations remote = new ChannelFactory<IRemoteOperations> (binding, address).CreateChannel();</div></div><div><span class="Apple-tab-span" style="white-space:pre">       </span>remote.CallMyMethodGeneratingBigData();</div>

<div><br></div>
<div><br></div><div>This works as expected on .NET/Windows, but under mono I get the following exception:</div><div><br></div><div><div>Error : The message is too large.</div><div>  at System.ServiceModel.Channels.NetTcp.TcpBinaryFrameManager.ReadSizedChunk () [0x00039] in /usr/src/packages/BUILD/mono-2.10.9/mcs/class/System.ServiceModel/System.ServiceModel.Channels.NetTcp/TcpBinaryFrameManager.cs:202 </div>

<div>  at System.ServiceModel.Channels.NetTcp.TcpBinaryFrameManager.ReadSizedMessage () [0x00089] in /usr/src/packages/BUILD/mono-2.10.9/mcs/class/System.ServiceModel/System.ServiceModel.Channels.NetTcp/TcpBinaryFrameManager.cs:337 </div>

<div>  at System.ServiceModel.Channels.NetTcp.TcpDuplexSessionChannel.TryReceive (TimeSpan timeout, System.ServiceModel.Channels.Message& message) [0x00046] in /usr/src/packages/BUILD/mono-2.10.9/mcs/class/System.ServiceModel/System.ServiceModel.Channels.NetTcp/TcpDuplexSessionChannel.cs:171 </div>

<div>  at System.ServiceModel.Channels.DuplexChannelBase.Receive (TimeSpan timeout) [0x00000] in /usr/src/packages/BUILD/mono-2.10.9/mcs/class/System.ServiceModel/System.ServiceModel.Channels/DuplexChannelBase.cs:178 </div>

<div>  at System.ServiceModel.MonoInternal.ClientRuntimeChannel.RequestCorrelated (System.ServiceModel.Channels.Message msg, TimeSpan timeout, IOutputChannel channel) [0x00013] in /usr/src/packages/BUILD/mono-2.10.9/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:594 </div>

<div>  at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00019] in /usr/src/packages/BUILD/mono-2.10.9/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:584 </div>

<div>  at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (System.ServiceModel.Description.OperationDescription od, System.Object[] parameters) [0x00066] in /usr/src/packages/BUILD/mono-2.10.9/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:537 </div>

<div>  at System.ServiceModel.MonoInternal.ClientRuntimeChannel.DoProcess (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters) [0x00038] in /usr/src/packages/BUILD/mono-2.10.9/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:502 </div>

<div>  at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Process (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters) [0x0001c] in /usr/src/packages/BUILD/mono-2.10.9/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:479 </div>

</div><div><br></div><div><br></div><div>My mono source code skill are not (yet) good enough to dive very deep, but it looks like the "binding.MaxReceivedMessageSize" custom value is not honored.</div><div>Greping the sources (from mono 2.10.8 tarball), I realized that the file mcs/class/System.ServiceModel/System.ServiceModel.Channels.NetTcp/TcpBinaryFrameManager.cs has the following code (in my opinion, part of the problem is located line 201):</div>

<div><br></div><div><div>193                 public byte [] ReadSizedChunk ()</div><div>194                 {</div><div>195                         lock (read_lock) {</div><div>196 </div><div>197                         int length = reader.ReadVariableInt ();</div>

<div>198                         if (length == 0)</div><div>199                                 return empty_bytes;</div><div>200 </div><div>201                         if (length > 65536)</div><div>202                                 throw new InvalidOperationException ("The message is too large.");</div>

<div>203 </div><div>204                         byte [] buffer = new byte [length];</div><div>205                         for (int readSize = 0; readSize < length; )</div><div>206                                 readSize += reader.Read (buffer, readSize, length - readSize);</div>

<div>207                         return buffer;</div><div>208 </div><div>209                         }</div><div>210                 }</div></div><div><br></div><div><br></div><div>if I replace this 64k hard-coded value (in my case, to be 10x bigger) and recompile my mono instance, everything works as expected.</div>

<div><br></div><div>I guess there was a good reason to put an hardcoded value here, but then, what is supposed to happen for messages bigger than this value, when MaxReceivedMessageSize has been set appropriately?</div><div>

Should mono have a loop calling ReadSizedChunk to process chunks until we reach final size (reader.ReadVariableInt ())?</div><div>Or should the hardcoded 65536 be removed?</div><div><br></div><div>Many thanks for your help!</div>

<div><br></div><div>My version of Mono:</div><div><div>> mono -V</div><div>Mono JIT compiler version 2.10.9 (tarball Fri Jul 13 23:11:26 UTC 2012)</div><div>Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. <a href="http://www.mono-project.com">www.mono-project.com</a></div>

<div>        TLS:           __thread</div><div>        SIGSEGV:       altstack</div><div>        Notifications: epoll</div><div>        Architecture:  amd64</div><div>        Disabled:      none</div><div>        Misc:          debugger softdebug </div>

<div>        LLVM:          supported, not enabled.</div><div>        GC:            Included Boehm (with typed GC and Parallel Mark)</div></div><div><br></div><div><br></div><div><br></div><div>Matthieu Barthelemy</div>