title: Send SOAP messages via WCF with MTOM and Content-Transfer-Encoding: 7-bit
body: <p>I am trying to send a SOAP message via WCF to the IRS, and it keeps getting rejected because my MTOM attachment is formatted incorrectly. </p>
  
  <p>I've narrowed down the issue to my <code>Content-Transfer-Encoding</code> value. It is set to <code>Binary</code> (shorthand for <code>8-bit</code>). </p>
  
  <p>The IRS service wants me to use <code>7-bit</code>, with an 8-bit-encoded attachment (in other words, encode with UTF-8 and then guarantee that I'm not using any non-ASCII characters).</p>
  
  <p>I'm already using a custom message encoder in order to gzip my requests (responses come back plain-text, ugh). This is what my <code>WriteMessage</code> looks like right now.</p>
  
  <pre><code>public override ArraySegment&lt;byte&gt; WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset) {
      // get an instance of the underlying encoder
      var encoder = new MtomMessageEncodingBindingElement() {
              MessageVersion = MessageVersion.Soap11WSAddressing10,
              WriteEncoding = System.Text.Encoding.UTF8
          }.CreateMessageEncoderFactory().Encoder;
  
      // write the message contents
      var uncompressed = encoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset);
  
      // compresses the resulting byte array
      return CompressBuffer(uncompressed, bufferManager, messageOffset);
  }
  </code></pre>
  
  <p>Any ideas? When I change the <code>WriteEncoding</code> property to ASCII or UTF7 .NET throws an ArgumentException and tells me the format is not supported.</p>