簡體   English   中英

通過具有MTOM和Content-Transfer-Encoding的WCF發送SOAP消息:7位

[英]Send SOAP messages via WCF with MTOM and Content-Transfer-Encoding: 7-bit

我試圖通過WCF將SOAP消息發送到IRS,但由於我的MTOM附件格式錯誤,它一直被拒絕。

我已將問題縮小到我的Content-Transfer-Encoding值。 它設置為Binary8-bit簡寫)。

國稅局服務要我用7-bit ,與8位編碼的附件(換句話說,使用UTF-8編碼,然后保證,我沒有使用任何非ASCII字符)。

我已經在使用自定義消息編碼器來gzip我的請求(響應以純文本形式返回,)。 這就是我的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並告知我不支持該格式。

我將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的指南,更正所有問題,然后重試。” 這是因為IRS期望這樣做:

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" 

似乎WCF中的內置MTOM編碼器不會對與IRS服務兼容的請求進行編碼。 它對在base64編碼的請求中找到的所有內容進行編碼,包括簽名請求中的BinarySecurityToken。 通過創建自定義編碼器,我能夠獲得更接近IRS要求的請求。 在WriteMessage中,您可以添加和添加MIME分隔符並將其重新編碼為附件。 需要傳出郵件檢查器來正確設置標頭: https : //blogs.msdn.microsoft.com/carlosfigueira/2011/04/18/wcf-extensibility-message-inspectors/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM