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.
I've narrowed down the issue to my Content-Transfer-Encoding
value. It is set to Binary
(shorthand for 8-bit
).
The IRS service wants me to use 7-bit
, 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).
I'm already using a custom message encoder in order to gzip my requests (responses come back plain-text, ugh). This is what my WriteMessage
looks like right now.
public override ArraySegment<byte> 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);
}
Any ideas? When I change the WriteEncoding
property to ASCII or UTF7 .NET throws an ArgumentException and tells me the format is not supported.
I am using Java Apache CXF and WSS4J for the IRS solution, but if you are getting this error "The message was not formatted properly and/or cannot be interpreted. Please review the XML standards outlined in Section 3 of the AIR Submission Composition and Reference Guide located at https://www.irs.gov/for-Tax-Pros/Software-Developers/Information-Returns/Affordable-Care-Act-Information-Return-AIR-Program, correct any issues, and try again." it is because the IRS is expecting this: