Tuesday, December 25, 2007

WCF Message Size Tester

Recently on the WCF Forum someone suggested that WCF wasn't able to send messages larger than 2 GB, so I wrote up a little example to disprove this theory.  I was able to send a 500 GB message with no problems, and I'm guessing that if I let it run long enough, there will be no problem sending up to 8 million terabytes, the maximum size of a WCF message (Int64.MaxValue).

The main "trick" to sending messages larger than 2 GB is to change the binding's TransferMode from its default of TransferMode.Buffered to TransferMode.Streamed.  Besides enabling you to send messages with minimal in-memory overhead, this also allows you to set MaxReceivedMessageSize larger than 2 GB without WCF throwing an exception when it tries to build the channel stack.

It's worth noting that MaxReceivedMessageSize is enforced by WCF regardless of whether the TransferMode is Buffered or Streamed.  The same is true for SendTimeout and ReceiveTimeout, so these still need to be adjusted accordingly.

Stream-based messaging in WCF is typically accomplished by using service operations that take a Stream as the only parameter, return a Stream, or both.  So what kind of Stream should I ask WCF to send for me?  I wanted my example to run as fast as possible, which means I didn't want it to be touching the disk in order to send or receive messages.  And I don't have enough memory or address space to buffer a 500 GB MemoryStream.  So I created a little hack stream implementation whose Read method leaves the byte buffer untouched and simply returns the appropriate number of bytes "read".  This results in sending 500 GB of zeros. :-)

Download the example code here.

Tuesday, December 11, 2007

Rhino Mocks Quick Reference

Last week I gave a presentation on mock objects for Software Professionals of Alaska.  Once the PowerPointy hand-waving was out of the way, I illustrated the concepts with code examples using Rhino Mocks.  I thought I was well-versed in Rhino Mocks before I started, but in the process of preparing the presentation I realized there was a lot that I didn't know or had forgotten.  So I distilled all the main facts and features down into a 3-page quick reference of tables and example usage.  You might argue that 3 pages makes it a "slow reference," but regardless I still think it's useful to see all the basics stripped down to the bare minimum.  Much of the content came from the Rhino Mocks Documentation Wiki, so look there first if you need more details on a particular feature.

So without further ado, I present the Rhino Mocks 3.3 Quick Reference.  It includes:

  • the 3 different record/replay syntax styles
  • 4 types of mocks, 7 if you include MultiMocks
  • expectations and setup
  • methods
  • properties
  • events
  • exceptions
  • delegates
  • custom behavior
  • assert messages
  • ordered and unordered
  • repetition
  • the full set of argument constraints

Feedback is quite welcome.  Enjoy!