title: WCF call via MSMQ erratic
body: <p>The code is trivial so rather than explain, here's the relevant portion:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
    if ((Request.HttpMethod == "POST") &amp;&amp; (Request.ContentType == "text/xml"))
    {
      string filename = string.Format("{0:yyyyMMddHHmmss}.xml", DateTime.UtcNow);
      var path = Path.Combine(Request.MapPath("Chapters"), Request.Headers["X-MAC"]);
      Directory.CreateDirectory(path);
      string xml;
      using (ChapterWriterClient client = new ChapterWriterClient())
      using (StreamReader sr = new StreamReader(Request.InputStream))
      {
        xml = sr.ReadToEnd();
        client.Write(xml);
        System.Diagnostics.Trace.TraceInformation(xml);
      }
      Request.SaveAs(Path.Combine(path, filename), false);
    }
  </code></pre>
  
  <p>There's more but the rest of it works as expected.</p>
  
  <p>Here's the problem: the call <code>client.Write(string xml)</code> is erratic in whether it succeeds. </p>
  
  <p>Some known facts:</p>
  
  <ul>
  <li>No error is ever reported to the debugger or the event log</li>
  <li>Sometimes the XML makes it into the message queue and sometimes it doesn't</li>
  <li><code>Request.SaveAs(string filepath, bool includeHeaders)</code> call <em>always</em> succeeds and the resultant file always contains the expected XML. This has several important implications:
  <ul>
  <li>The call to WCF is being executed.</li>
  <li>Because the string <code>xml</code> had the expected value immediately after the failed WCF call, and assignment to this variable occurs only prior to the WCF call, it must have had the correct value at the time of the call.</li>
  </ul></li>
  </ul>
  
  <p>There is some variation in message size so I'm checking the service config in that regard but past experience tells me to expect an exception thrown when the payload is too big.</p>
  
  <p>Any clues would be appreciated.</p>
  
  <p>Also, as you can probably see the whole point of the exercise is a somewhat naiive attempt to use an HTTP POST to put some XML into a message on MSMQ. I'd be perfectly happy with a "Don't do it like that, do it like this you ignorant savage" type answer.</p>