1

我正在尝试通过 WCF 向 IRS 发送 SOAP 消息,但由于我的 MTOM 附件格式不正确,它一直被拒绝。

我已将问题范围缩小到我的Content-Transfer-Encoding价值。它设置为Binary(的简写8-bit)。

IRS 服务希望我使用7-bit8 位编码附件(换句话说,使用 UTF-8 编码,然后保证我没有使用任何非 ASCII 字符)。

我已经在使用自定义消息编码器来压缩我的请求(回复以纯文本形式返回,呃)。这就是我WriteMessage现在的样子。

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);
}

有任何想法吗?当我将WriteEncoding属性更改为 ASCII 或 UTF7 时,.NET 会引发 ArgumentException 并告诉我不支持该格式。

4

2 回答 2

2

WCF 中的内置 MTOM 编码器似乎不会对与 IRS 服务兼容的请求进行编码。它对它在请求中找到的任何内容进行编码,这些请求是 base64 编码的,包括签名请求中的 BinarySecurityToken。通过创建自定义编码器,我能够获得更接近 IRS 要求的请求。在 WriteMessage 中,您可以附加和前置 MIME 分隔符,并将文件重新编码为附件。需要传出消息检查器才能正确设置标头:https ://blogs.msdn.microsoft.com/carlosfigueira/2011/04/18/wcf-extensibility-message-inspectors/

于 2016-02-04T17:18:06.093 回答
1

我将 Java Apache CXF 和 WSS4J 用于 IRS 解决方案,但如果您收到此错误“消息格式不正确和/或无法解释。请查看 AIR 提交组合和参考第 3 节中概述的 XML 标准位于https://www.irs.gov/for-Tax-Pros/Software-Developers/Information-Returns/Affordable-Care-Act-Information-Return-AIR-Program的指南,更正任何问题,然后重试。” 这是因为美国国税局期待这一点:

Content-Type: application/xml
Content-Transfer-Encoding: 7bit
Content-ID: <6920edd2-a3c7-463b-b336-323a422041d4-1@blahurn:us:gov:treasury:irs:common>
Content-Disposition: attachment;name="1094B_Request_BBBBB_20151019T121002000Z.xml" 
于 2016-01-28T22:13:22.347 回答