5

BulkRequestTransmitter Web サービスを介して送信しようとすると、次のエラーが表示されます。コンポジション ガイドは、このメッセージに関する限りあまり役に立ちません。私の SOAP XML とコンポジション ガイドの SOAP を比較すると、同じように見えます。別の目で問題がどこにあるかを確認できることを願っています。

メッセージが適切にフォーマットされていないか、解釈できません。https://www.irs.gov/for-Tax-Pros/Software-Developers/Information-Returns/Affordable-Care-Act-Informationにある AIR Submission Composition and Reference Guide のセクション 3 で概説されている XML 標準を確認してください。 -Return-AIR-Program、問題を修正し、再試行してください。

私が試したこと:

  • SOAP エンベロープで空白を使用して (空白を使用せずに) 送信しようとしました。
  • Form Data XML を XML 形式で送信しようとしました。
  • フォーム データの形式で送信しようとしましたbase64string(この送信はそうでした)。
  • dsSignature 要素にプレフィックスを追加しました。この SO 投稿を使用して、署名要素にプレフィックスを追加しました。
  • 「プリティ プリント」形式のフォーム データを、更新された構成ガイド (v4.2) に従って追加しました。
  • 構成ガイドのセクション10.3で概説されMIMEている要求のフォーマットをコピーしました。BulkTransmitterService
  • 2 つのソリューションを作成しました。1.) SOAP 要求に必要な XML を手動で作成し、HttpWebRequestオブジェクトを介して送信します。WSDL2.)としてプロジェクトにインポートされた を介して送信要求を送信し、Service Referenceカスタム エンコーダを使用しGZip and Mtom Encodingて、SOAP ステータス要求 ( を介して送信HttpWebRequest) に必要な XML を手動で作成します。

更新 #1
いくつかの新しい追加に基づいて要求を更新しました。

  • dsSignature 要素にプレフィックスを追加しました。
  • 「プリティ プリント」形式のフォーム データを、更新された構成ガイド (v4.2: セクション 5.4.2) に従って追加しました。

更新 #2必要に応じてスキーマ参照をインポートする Visual Studio の新しいインスタンス内で .xml ファイル
を手動で作成し始めました。私はこれをあらゆる種類のアプリケーション作成の外で行っていますSOAP

そうすることでSOAP、アプリケーションを介して作成してい. 私が見つけたバグはマニフェスト XML 内にあり、IRS スキーマに準拠していませんでした。

今後 24 時間以内にこれらを調査し、それに応じて更新します。

  • には またはのいずれかurn:MailingAddressGrpの子が必要です。その子には、適切な住所要素が含まれている必要があります。私のコードには現在、の直接の子がありません。urn:USAddressGrpurn:ForeignAddressGrpurn:MailingAddressGrp
  • urn1:DocumentSystemFileNmof の値Form1094C_Request_[TCC]_yyyyMMddThhmmssfffZ.xmlが正しくありません。それがどうあるべきか、まだ完全にはわかりません。
  • 要素には、私が持っている要素にurn1:BulkExchangeFile関連する問題xop:Includeがあります。スキーマは base64Binary タイプを必要としています。

アップデート #2.5

  • USAddressGrp要素を含めるように XML 生成プロセスを更新しました。
  • ミリ秒単位で 1 文字余分にあることがわかりました (3 文字ではなく 4 文字)。これを修正し、ファイル名の先頭から文字列「Form」を削除すると、 の値がurn1:DocumentSystemFileNmスキーマに対して正常に検証されました。

アップデート #3

  • 私が行った更新に基づいて完全な要求を更新しました。現時点では、リクエストの何が問題なのかを推測できません。誰かが何かギラギラしているのを見たら、助けてください!

アップデート #4

  • 行われた追加の更新に基づいて完全な要求を更新しました。ds別の SO ユーザーのフィードバックに基づいて、署名からプレフィックスを削除しました。dsこのユーザーは、事後にプレフィックスを署名に追加して署名を再計算することなく、これらの要求を機能させることができます。

    SO ユーザーはまた、 <inc:Include>要素の子要素として設定されている要素 で自分の要求が機能していることを確認しました<BulkExchangeFile>

  • MIME構成ガイドのセクション 10.3 のサンプルに従って、ヘッダーが正しいことを確認しました。

アップデート #5

  • 現在、2 つの解決策があります。1 つは、SOAP 要求に必要な XML を手動で作成して送信しHttpWebRequest、. もう 1 つはWSDL Service Reference、送信リクエストに を使用し、以下に概説するカスタム エンコーダーを使用して、ステータスの SOAP リクエストに必要な XML を手動で作成します。

    この更新の時点で、解決策 1 では、送信リクエストを行うと上記のエラーが表示され、ステータス リクエストを行うと以下のエラーが表示されます。ただし、ソリューション 2 を使用すると、両方の要求 (送信とステータス) で以下のエラーが表示されます。

    証明書の問題の可能性を調べて、これらの解決策のいずれかで進展があるかどうかを確認しています。

更新 #6

私が遭遇した多くの問題があり、それにより私は遅れました。核心的な詳細は省きますが、要するに、セキュリティ証明書が IRS システムに登録されておらず、証明書が適切にインストールされていなかったため、 を通じて情報にアクセスできませんでしたX509Store。最後に、これらの作業が完了し、サーバーから IRS にデータを送信するテストを行うことができました (対、適切な証明書を持たないローカル マシン)。残念ながら、以下に詳述する WS-Security エラーが引き続き表示されます。現在送信しているもので完全なリクエストを更新しました。

次のメッセージでエラーが発生しました: メッセージ内の WS セキュリティ ヘッダーが無効です。https://www.irs.gov/for-Tax-Pros/Software-Developers/Information-Returns/Affordable-Care-Act-Informationにある AIR Submission Composition and Reference Guide のセクション 5 に記載されている送信手順を確認してください。 -Return-AIR-Program、問題を修正し、再試行してください。


MIME ヘッダーのすべての改行は現状のままであり、改行は想定どおりのものだと思います。 FormData 添付ファイルは Pretty Print として送信されますが、SOAP エンベロープはそうではありません。この投稿の SOAP エンベロープは、読みやすいように書式設定されています。

更新 #7:

ユーザーに感謝します: jstill と FatherOfWine に彼らが以下に投稿した内容を提供し、Bon にこのプロジェクトの以前の支援を提供してくれました。提出物を機能させるために、1 つの壁を突破しました。それは今働いています。ステータスリクエストも機能しています。ただし、ステータスと添付ファイル (エラー データ ファイル) を取り出すには、それを処理する方法を理解する必要があります。

完全なリクエスト:

Content-Encoding: gzip
Accept-Encoding: gzip, deflate
Content-Type: multipart/related; type="application/xop+xml"; start="<rootpart>"; start-info="text/xml"; boundary="MIME_boundary"
SOAPAction: BulkRequestTransmitter
MIME-Version: 1.0
Host: la.www4.irs.gov

--MIME_Boundary
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: 8bit
Content-Id: <root_part>

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
        <Security xmlns:h="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <Signature Id="SIG-E77c57b78ebc54e989bfc9e43604a04a4" xmlns="http://www.w3.org/2000/09/xmldsig#">
                <SignedInfo>
                    <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#WithComments" />
                    <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
                    <Reference URI="#TS-Eb4799bee41bb4df0a72f52832d283ef7">
                        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                        <DigestValue>[TimestampDigestValue]</DigestValue>
                    </Reference>
                    <Reference URI="#id-E5f1ed32aab8f4578adeee5debd851a62">
                        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                        <DigestValue>[ACABusinessHeaderDigestValue]</DigestValue>
                    </Reference>
                    <Reference URI="#id-E4a71164001994d7f865fc7ddb8055350">
                        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                        <DigestValue>[ManifestDigestValue]</DigestValue>
                    </Reference>
                </SignedInfo>
                <SignatureValue>[SignatureValue]</SignatureValue>
                <KeyInfo Id="KI-E2309cb142e1a4076a2e71373e6e6b75f">
                    <SecurityTokenReference d6p1:Id="STR-E2751169ee468470290fe5e8bfb34589e" xmlns:d6p1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                        <KeyIdentifier EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">[KeyIdentifier]</KeyIdentifier>
                    </SecurityTokenReference>
                </KeyInfo>
            </Signature>
            <a:Timestamp a:Id="TS-Eb4799bee41bb4df0a72f52832d283ef7" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                <a:Created>2016-05-18T09:51:05.856Z</a:Created>
                <a:Expires>2016-05-18T10:01:05.856Z</a:Expires>
            </a:Timestamp>
        </Security>
        <ACATransmitterManifestReqDtl a:Id="id-E4a71164001994d7f865fc7ddb8055350" xmlns:h="urn:us:gov:treasury:irs:ext:aca:air:7.0" xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns="urn:us:gov:treasury:irs:ext:aca:air:7.0">
            <PaymentYr>2015</PaymentYr>
            <PriorYearDataInd>0</PriorYearDataInd>
            <EIN xmlns="urn:us:gov:treasury:irs:common">000000301</EIN>
            <TransmissionTypeCd>O</TransmissionTypeCd>
            <TestFileCd>T</TestFileCd>
            <OriginalReceiptId />
            <TransmitterNameGrp>
                <BusinessNameLine1Txt />
            </TransmitterNameGrp>
            <CompanyInformationGrp>
                <CompanyNm>Selitestthree</CompanyNm>
                <MailingAddressGrp>
                    <USAddressGrp>
                        <AddressLine1Txt>6689 Willow Court</AddressLine1Txt>
                        <CityNm xmlns="urn:us:gov:treasury:irs:common">Beverly Hills</CityNm>
                        <USStateCd>CA</USStateCd>
                        <USZIPCd xmlns="urn:us:gov:treasury:irs:common">90211</USZIPCd>
                    </USAddressGrp>
                </MailingAddressGrp>
                <ContactNameGrp>
                    <PersonFirstNm>Rose</PersonFirstNm>
                    <PersonLastNm>Lincoln</PersonLastNm>
                </ContactNameGrp>
                <ContactPhoneNum>5559876543</ContactPhoneNum>
            </CompanyInformationGrp>
            <VendorInformationGrp>
                <VendorCd>I</VendorCd>
                <ContactNameGrp>
                    <PersonFirstNm>ContactFirstName</PersonFirstNm>
                    <PersonLastNm>ContactLastName</PersonLastNm>
                </ContactNameGrp>
                <ContactPhoneNum>ContactPhoneNumber</ContactPhoneNum>
            </VendorInformationGrp>
            <TotalPayeeRecordCnt>3</TotalPayeeRecordCnt>
            <TotalPayerRecordCnt>1</TotalPayerRecordCnt>
            <SoftwareId>PPACA</SoftwareId>
            <FormTypeCd>1094/1095C</FormTypeCd>
            <BinaryFormatCd xmlns="urn:us:gov:treasury:irs:common">application/xml</BinaryFormatCd>
            <ChecksumAugmentationNum xmlns="urn:us:gov:treasury:irs:common">6b2512ce28f603f76261923d297738e5</ChecksumAugmentationNum>
            <AttachmentByteSizeNum xmlns="urn:us:gov:treasury:irs:common">14076</AttachmentByteSizeNum>
            <DocumentSystemFileNm>1094C_Request_[TCC]_20160518T215105716Z.xml</DocumentSystemFileNm>
        </ACATransmitterManifestReqDtl>
        <ACABusinessHeader a:Id="id-E5f1ed32aab8f4578adeee5debd851a62" xmlns:h="urn:us:gov:treasury:irs:msg:acabusinessheader" xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns="urn:us:gov:treasury:irs:msg:acabusinessheader">
            <UniqueTransmissionId xmlns="urn:us:gov:treasury:irs:ext:aca:air:7.0">51958882-c653-4eab-8dfb-287ecc555aaa:SYS12:[TCC]::T</UniqueTransmissionId>
            <Timestamp xmlns="urn:us:gov:treasury:irs:common">2016-05-18T14:51:05.8568594-07:00</Timestamp>
        </ACABusinessHeader>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <ACABulkRequestTransmitter xmlns="urn:us:gov:treasury:irs:msg:irsacabulkrequesttransmitter" version="1.0">
            <BulkExchangeFile xmlns="urn:us:gov:treasury:irs:common">
                <inc:Include href="cid:1094C_Request_BB0S4_20160518T215105716Z.xml" xmlns:inc="http://www.w3.org/2004/08/xop/include" />
            </BulkExchangeFile>
        </ACABulkRequestTransmitter>
    </s:Body>
</s:Envelope>

--MIME_Boundary
Content-Type: text/xml; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Id: <1094C_Request_[TCC]_20160518T215105716Z.xml>
Content-Disposition: attachment; name="1094C_Request_[TCC]_20160518T215105716Z.xml"

[PrettyPrintFormDataXml]
--MIME_boundary--
4

6 に答える 6

3

まず、簡単な免責事項です。この回答は、fatherOfWine、Russ、および Bon がこの質問と他の SO の質問にわたって提供した素晴らしいものによって可能になりました。私が実際に行ったのは、彼らからたくさんのものを組み合わせて、それが機能するまでまだ抱えていた問題をハックすることだけでした. さらに重要なことは、ここで提供されているコードは不適切であり、そのまま使用するべきではないということです。何が機能するかがわかったので、これをかなりクリーンアップする予定です。これを使用している人は誰でも同じことをすることをお勧めします。これを見ている人なら誰でもすぐに思いつくであろう重要なことは、私がパイプライン全体を通して物事に到達するための簡単なハックとして使用した大量の静的変数です。真剣に、これを本番環境でそのまま使用しないでください、それは何かが動かなくなるまで何時間も壁に物を投げつけた結果ですが、何かをより良くするための良い出発点を提供するはずです.


ここにすべてを含めるにはコードが多すぎるため、いくつかのハイライトと一般的な発見について説明し、VS ソリューションへのリンクを含めます。

  1. TCC とその他のさまざまな ID が既に設定されていること、適切な種類の証明書を購入したこと (このドキュメントの 41 ページ)、証明書を適切に登録したこと (このドキュメントを参照)を確認してください。
  2. メッセージを受け入れるには、soap エンベロープ内のすべての CR-LF を削除する必要があることがわかりました。そこにあると、「予期しない子要素」などのいくつかの要素でエラーが発生します。
  3. ドキュメントはいくつかの場所で矛盾しており ( 74ページと84ページを参照し、例として BulkExchangeFile 要素に含める必要があると書かれている内容を参照してください)、wsdl/xsds もまったく間違っています。どういうわけか古いものを持っていたのかもしれませんが、彼らの側のサービスが実際に受け入れるものを見つけるまで、変更を加えて試してみる必要がありました.
  4. keyinfo を signedxml セクションに適切に追加すること、そこにあるすべての参照が正しく構築され、適切な InclusiveNamespaces リストが含まれていること、ComputeSignature を呼び出したら、エンベロープに行う変更は署名を追加することだけであることが非常に重要です。それに要素。
  5. signature 要素について言えば、security 要素内の timestamp 要素の後にある場合、IRS システムはエラーを返します。それは最初でなければなりません。
  6. 署名参照の生成に関しては、名前空間の接頭辞が非常に重要だったので、エンベロープ xml を手動で構築するルートに進みました。それでも、XSD やドキュメントの一部のページで、サービスが実際に望んでいたものとは異なると述べていたため、テスト中にプレフィックスを変更しなければならなかった要素がいくつかありました。幸いなことに、サービスによって返された障害は、値が期待されている名前空間を示すことで、実際にいくらかの助けになりました。
  7. すべての gzip と MTOM のセットアップを取得する以外に (fatherOfWine の助けに感謝します)、最終的に機能したことの大部分は、単一の汎用クラス (巧妙に "General" と呼びました) で行われます。繰り返しますが、これは悪いコードであり、何か (何でも!) を正しく動作させる必要があるだけの結果でした。先に進み、ここで回答に含めますが、簡単な「ああ!」が提供される場合に備えて。この問題に取り組んでいる他の人に。

    using System;
    using System.IO;
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    using System.Security.Cryptography.Xml;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.Text;
    using System.Xml;
    using IrsAcaClient.ACABulkRequestTransmitterService;
    
    namespace IrsAcaClient
    {
    public class General
    {
        /*****************************************************
         * 
         * What I'm doing here (with static vars) is VERY BAD but this whole thing is just a dirty hack for now.
         * Hopefully I can clean this up later.
         * - JRS 2016-05-10
         * 
         *****************************************************/
        public const string SecurityTimestampStringFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffZ";
    
        public const string EnvelopeContentID = "<rootpart>";
    
        public static string AttachmentFilePath;
    
        public static string AttachmentFileName { get { return Path.GetFileName(General.AttachmentFilePath); } }
        public static string AttachmentContentID {get { return string.Format("<{0}>", General.AttachmentFileName); }}
    
        public const string MIMEBoundary = "MIME_boundary";
    
        public static string TCCode;
    
        public static Guid TransmissionGuid;
    
        public static string UniqueTransmissionId
        {
            get { return string.Format("{0}:SYS12:{1}::T", TransmissionGuid, TCCode); }
        }
    
        public static string SecurityTimeStampWsuId;
        public static string ManifestWsuId;
        public static string BusinessHeaderWsuId;
        public static string SignatureWsuId;
    
        public static string CertificatePath;
        public static string CertificatePassword;
    
        public static DateTime SecurityTimestampUTC;
    
        private static string _replacementSoapEnvelope;
    
        public static string ReplacementSoapEnvelope{get { return _replacementSoapEnvelope; }}
    
        private static void GenerateReference(string elementID, string inclusivePrefixList, SignedXmlWithId xSigned)
        {
            var reference = new Reference()
            {
                Uri = "#" + elementID
            };
    
            XmlDsigExcC14NTransform env = new XmlDsigExcC14NTransform();
            env.InclusiveNamespacesPrefixList = inclusivePrefixList;
            reference.AddTransform(env);
    
            xSigned.AddReference(reference);
        }
    
        public static string GetAttachmentFileContent()
        {
            //probably not ideal
            return File.ReadAllText(AttachmentFilePath);
        }
    
        public static string GetFileName()
        {
            //TODO: this may need to be tweaked slightly from the real filename
            return General.AttachmentFileName;
        }
    
        public static string GenerateWsuId(string prefix)
        {
            return string.Format("{0}-{1}", prefix, Guid.NewGuid().ToString().Replace("-", "").ToUpper());
        }
    
        internal static void GenerateReplacementSoapEnvelope(ACABulkRequestTransmitterService.SecurityHeaderType securityHeader, ACABulkRequestTransmitterService.ACABulkBusinessHeaderRequestType businessHeader, ACABulkRequestTransmitterService.ACATrnsmtManifestReqDtlType manifest, ACABulkRequestTransmitterService.ACABulkRequestTransmitterType bulkTrans)
        {
            //load the base envelope xml
            var doc = new XmlDocument();
            doc.PreserveWhitespace = false;
            doc.Load("BaseSoapEnvelope.xml");
    
            /* Need a bunch of namespaces defined
             * xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
             * xmlns:urn="urn:us:gov:treasury:irs:ext:aca:air:7.0"
             * xmlns:urn1="urn:us:gov:treasury:irs:common"
             * xmlns:urn2="urn:us:gov:treasury:irs:msg:acabusinessheader"
             * xmlns:urn3="urn:us:gov:treasury:irs:msg:irsacabulkrequesttransmitter"
             * xmlns:wsa="http://www.w3.org/2005/08/addressing"
             * xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
             * xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
             * xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
             * xmlns:xop="http://www.w3.org/2004/08/xop/include"
             */
            XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);
            nsMgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
            nsMgr.AddNamespace("urn", "urn:us:gov:treasury:irs:ext:aca:air:7.0");
            nsMgr.AddNamespace("urn1", "urn:us:gov:treasury:irs:common");
            nsMgr.AddNamespace("urn2", "urn:us:gov:treasury:irs:msg:acabusinessheader");
            nsMgr.AddNamespace("urn3", "urn:us:gov:treasury:irs:msg:irsacabulkrequesttransmitter");
            nsMgr.AddNamespace("wsa", "http://www.w3.org/2005/08/addressing");
            nsMgr.AddNamespace("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
            nsMgr.AddNamespace("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
            nsMgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
            nsMgr.AddNamespace("xop","http://www.w3.org/2004/08/xop/include");
    
    
            //start replacing values in it
            //for securityHeader, should have the following
            /*
             * securityHeader.Signature.Id
             * securityHeader.Timestamp.Id
             * securityHeader.Timestamp.Created.Value
             * securityHeader.Timestamp.Expires.Value
             */
            //doc.SelectSingleNode("//wsse:Security/ds:Signature", nsMgr).Attributes["Id"].Value = securityHeader.Signature.Id;
            doc.SelectSingleNode("//wsse:Security/wsu:Timestamp", nsMgr).Attributes["wsu:Id"].Value = securityHeader.Timestamp.Id;
            doc.SelectSingleNode("//wsse:Security/wsu:Timestamp/wsu:Created", nsMgr).InnerText = securityHeader.Timestamp.Created.Value;
            doc.SelectSingleNode("//wsse:Security/wsu:Timestamp/wsu:Expires", nsMgr).InnerText = securityHeader.Timestamp.Expires.Value;
    
    
            //for businessHeader, should have the following
            /*
             * businessHeader.UniqueTransmissionId
             * businessHeader.Timestamp
             * businessHeader.Id 
             */
            doc.SelectSingleNode("//urn2:ACABusinessHeader", nsMgr).Attributes["wsu:Id"].Value = businessHeader.Id;
            doc.SelectSingleNode("//urn2:ACABusinessHeader/urn:UniqueTransmissionId", nsMgr).InnerText = businessHeader.UniqueTransmissionId;
            doc.SelectSingleNode("//urn2:ACABusinessHeader/urn1:Timestamp", nsMgr).InnerText = businessHeader.Timestamp.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ssZ");
    
    
            //for manifest, should have the following, some of which will need some conversions
            /*
             * manifest.Id
             * manifest.BinaryFormatCd - convert from enum
             * manifest.PaymentYr
             * manifest.PriorYearDataInd - convert from enum
             * manifest.EIN
             * manifest.TransmissionTypeCd - convert from enum
             * manifest.TestFileCd
             * manifest.TransmitterNameGrp.BusinessNameLine1Txt
             * manifest.CompanyInformationGrp.CompanyNm
             * manifest.CompanyInformationGrp.MailingAddressGrp.Item.AddressLine1Txt
             * manifest.CompanyInformationGrp.MailingAddressGrp.Item.CityNm
             * manifest.CompanyInformationGrp.MailingAddressGrp.Item.USStateCd - convert from enum
             * manifest.CompanyInformationGrp.MailingAddressGrp.Item.USZIPCd
             * manifest.CompanyInformationGrp.ContactNameGrp.PersonFirstNm
             * manifest.CompanyInformationGrp.ContactNameGrp.PersonLastNm
             * manifest.CompanyInformationGrp.ContactPhoneNum
             * manifest.VendorInformationGrp.VendorCd
             * manifest.VendorInformationGrp.ContactNameGrp.PersonFirstNm
             * manifest.VendorInformationGrp.ContactNameGrp.PersonLastNm
             * manifest.VendorInformationGrp.ContactPhoneNum
             * manifest.TotalPayeeRecordCnt
             * manifest.TotalPayerRecordCnt
             * manifest.SoftwareId
             * manifest.FormTypeCd - convert from enum
             * manifest.ChecksumAugmentationNum
             * manifest.AttachmentByteSizeNum
             * manifest.DocumentSystemFileNm
             */
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl", nsMgr).Attributes["wsu:Id"].Value = manifest.Id;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:PaymentYr", nsMgr).InnerText = manifest.PaymentYr;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:PriorYearDataInd", nsMgr).InnerText = manifest.PriorYearDataInd.GetXmlEnumAttributeValueFromEnum();
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn1:EIN", nsMgr).InnerText = manifest.EIN;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:TransmissionTypeCd", nsMgr).InnerText = manifest.TransmissionTypeCd.ToString();
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:TestFileCd", nsMgr).InnerText = manifest.TestFileCd;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:TransmitterNameGrp/urn:BusinessNameLine1Txt", nsMgr).InnerText = manifest.TransmitterNameGrp.BusinessNameLine1Txt;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:CompanyInformationGrp/urn:CompanyNm", nsMgr).InnerText = manifest.CompanyInformationGrp.CompanyNm;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:CompanyInformationGrp/urn:MailingAddressGrp/urn:USAddressGrp/urn:AddressLine1Txt", nsMgr).InnerText = ((USAddressGrpType)manifest.CompanyInformationGrp.MailingAddressGrp.Item).AddressLine1Txt;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:CompanyInformationGrp/urn:MailingAddressGrp/urn:USAddressGrp/urn1:CityNm", nsMgr).InnerText = ((USAddressGrpType)manifest.CompanyInformationGrp.MailingAddressGrp.Item).CityNm;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:CompanyInformationGrp/urn:MailingAddressGrp/urn:USAddressGrp/urn:USStateCd", nsMgr).InnerText = ((USAddressGrpType)manifest.CompanyInformationGrp.MailingAddressGrp.Item).USStateCd.ToString();
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:CompanyInformationGrp/urn:MailingAddressGrp/urn:USAddressGrp/urn1:USZIPCd", nsMgr).InnerText = ((USAddressGrpType)manifest.CompanyInformationGrp.MailingAddressGrp.Item).USZIPCd;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:CompanyInformationGrp/urn:ContactNameGrp/urn:PersonFirstNm", nsMgr).InnerText = manifest.CompanyInformationGrp.ContactNameGrp.PersonFirstNm;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:CompanyInformationGrp/urn:ContactNameGrp/urn:PersonLastNm", nsMgr).InnerText = manifest.CompanyInformationGrp.ContactNameGrp.PersonLastNm;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:CompanyInformationGrp/urn:ContactPhoneNum", nsMgr).InnerText = manifest.CompanyInformationGrp.ContactPhoneNum;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:VendorInformationGrp/urn:VendorCd", nsMgr).InnerText = manifest.VendorInformationGrp.VendorCd;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:VendorInformationGrp/urn:ContactNameGrp/urn:PersonFirstNm", nsMgr).InnerText = manifest.VendorInformationGrp.ContactNameGrp.PersonFirstNm;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:VendorInformationGrp/urn:ContactNameGrp/urn:PersonLastNm", nsMgr).InnerText = manifest.VendorInformationGrp.ContactNameGrp.PersonLastNm;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:VendorInformationGrp/urn:ContactPhoneNum", nsMgr).InnerText = manifest.VendorInformationGrp.ContactPhoneNum;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:TotalPayeeRecordCnt", nsMgr).InnerText = manifest.TotalPayeeRecordCnt;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:TotalPayerRecordCnt", nsMgr).InnerText = manifest.TotalPayerRecordCnt;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:SoftwareId", nsMgr).InnerText = manifest.SoftwareId;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:FormTypeCd", nsMgr).InnerText = manifest.FormTypeCd.GetXmlEnumAttributeValueFromEnum();
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn1:BinaryFormatCd", nsMgr).InnerText = manifest.BinaryFormatCd.GetXmlEnumAttributeValueFromEnum();
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn1:ChecksumAugmentationNum", nsMgr).InnerText = manifest.ChecksumAugmentationNum;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn1:AttachmentByteSizeNum", nsMgr).InnerText = manifest.AttachmentByteSizeNum;
            doc.SelectSingleNode("//urn:ACATransmitterManifestReqDtl/urn:DocumentSystemFileNm", nsMgr).InnerText = manifest.DocumentSystemFileNm;
    
    
            //for bulkTrans, should have the following
            /*
             * bulkTrans.BulkExchangeFile.Include.href
             */
            doc.SelectSingleNode("//urn3:ACABulkRequestTransmitter/urn1:BulkExchangeFile/xop:Include", nsMgr).Attributes["href"].Value = bulkTrans.BulkExchangeFile.Include.href;
    
    
            //now do some more security setup
            var cert = new X509Certificate2(CertificatePath, CertificatePassword, X509KeyStorageFlags.MachineKeySet);
    
            var exported = cert.Export(X509ContentType.Cert, CertificatePassword);
            var base64 = Convert.ToBase64String(exported);
    
            //now compute all the signing stuff
            var xSigned = new SignedXmlWithId(doc);
            xSigned.Signature.Id = securityHeader.Signature.Id;
    
            // Add the key to the SignedXml document.
            xSigned.SigningKey = cert.PrivateKey;
            xSigned.Signature.Id = SignatureWsuId;
            xSigned.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NWithCommentsTransformUrl;
    
            var keyInfo = new KeyInfo
            {
                Id = GenerateWsuId("KI")
            };
    
            //need to get the keyinfo into the signed xml stuff before we compute sigs, and because it is using some stuff that
            //doesn't appear to be supported out of the box we'll work around it by adding a node directly
            var sbKeyInfo = new StringBuilder();
            sbKeyInfo.Append("<root xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">");
            sbKeyInfo.Append("<wsse:SecurityTokenReference wsu:Id=\"" + GenerateWsuId("STR") + "\">");
            sbKeyInfo.Append("<wsse:KeyIdentifier EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\" ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\">" + base64.ToString());
            sbKeyInfo.Append("</wsse:KeyIdentifier>");
            sbKeyInfo.Append("</wsse:SecurityTokenReference>");
            sbKeyInfo.Append("</root>");
            XmlDocument tempDoc = new XmlDocument();
            tempDoc.LoadXml(sbKeyInfo.ToString());
    
            keyInfo.AddClause(new KeyInfoNode((XmlElement)tempDoc.FirstChild.FirstChild));
    
            xSigned.KeyInfo = keyInfo;
    
            GenerateReference(SecurityTimeStampWsuId, "wsse wsa soapenv urn urn1 urn2 urn3", xSigned);
            GenerateReference(BusinessHeaderWsuId, "wsa soapenv urn urn1 urn3", xSigned);
            GenerateReference(ManifestWsuId, "wsa soapenv urn1 urn2 urn3", xSigned);
    
            // Compute the Signature.
            xSigned.ComputeSignature();
    
            //signing stuff must come before the timestamp or the IRS service complains
            doc.SelectSingleNode("//wsse:Security", nsMgr).InsertBefore(xSigned.GetXml(), doc.SelectSingleNode("//wsse:Security", nsMgr).FirstChild);
    
            //
            _replacementSoapEnvelope = doc.OuterXml;
        }
    
        public static ACABulkRequestTransmitterResponseType Run(ACABulkRequestTransmitterService.SecurityHeaderType securityHeader, ACABulkRequestTransmitterService.ACABulkBusinessHeaderRequestType businessHeader, ACABulkRequestTransmitterService.ACATrnsmtManifestReqDtlType manifest, ACABulkRequestTransmitterService.ACABulkRequestTransmitterType bulkTrans)
        {
            //had some issues early on with the cert on the IRS server, this should probably be removed and retested without it
            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3 |
                                                   SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
    
            var acaSecurityHeader = new ACABulkRequestTransmitterService.TransmitterACASecurityHeaderType(); //leave this empty for transmitting via ISS-A2A
    
            var requestClient = new ACABulkRequestTransmitterService.BulkRequestTransmitterPortTypeClient("BulkRequestTransmitterPort");
    
            requestClient.Endpoint.Contract.ProtectionLevel = System.Net.Security.ProtectionLevel.None;
            //var vs = requestClient.Endpoint.Behaviors.Where((i) => i.GetType().Namespace.Contains("VisualStudio"));
            //if (vs != null)
            //    requestClient.Endpoint.Behaviors.Remove((System.ServiceModel.Description.IEndpointBehavior)vs.Single());
    
            //generate the real envelope we want
            GenerateReplacementSoapEnvelope(securityHeader, businessHeader, manifest, bulkTrans);
    
            using (var scope = new OperationContextScope(requestClient.InnerChannel))
            {
    
                //Adding proper HTTP Header to an outgoing requqest.
                HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
    
                requestMessage.Headers["Content-Encoding"] = "gzip";
                requestMessage.Headers["Content-Type"] = string.Format(@"multipart/related; type=""application/xop+xml"";start=""{0}"";start-info=""text/xml"";boundary=""{1}""", General.EnvelopeContentID, General.MIMEBoundary);
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
    
                var response = requestClient.BulkRequestTransmitter(acaSecurityHeader,
                                                                    securityHeader,
                                                                    ref businessHeader,
                                                                    manifest,
                                                                    bulkTrans);
    
                //we got a response!  now do something with it
                return response;
    
            }
        }
    }
    

ここに完全なソリューションがあります。提供されたすべての独自のデータが必要です (すべての受取人および支払人の記録を含む完全な添付ファイルを含みます。これはこの範囲外ですが、生成するのは非常に簡単なはずです)。また、これはフォームの送信のみであり、ステータス チェックではないことにも注意してください。それが機能するようになったら、この回答を返して更新することを忘れないようにします(ただし、他の誰かがすでにそれを持っていて共有したい場合は、それもかなり素晴らしいでしょう)。


ステータス サービスの編集

メッセージを取得して応答を処理するために、wsdl と独自のジャンク コードから生成されたクラスのクリーンアップ バージョンを組み合わせました。これはまだ 100% テストされておらず、サニティ チェックなどが必要であることに注意してください。ここでの使用法は非常に簡単です。

var statusResponse = StatusService.CheckStatus(receipt, tCCode, certificatePath, certificatePassword, "https://la.www4.irs.gov/airp/aca/a2a/1095BC_Status_Request_AATS2016");

そして、ここに完全なクラスがあります (生成されたクラスの名前空間のボーナス付き):

ステータス サービス コードについては、2 番目の回答を参照してください

于 2016-05-20T13:25:11.253 に答える
2

消える可能性のある別のリンクではなく、ステータスサービスを含めるように数秒答えます。

メインクラスは次のとおりです。

using System;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Serialization;

namespace IrsAcaClient
{
    public class StatusService
    {
        private const string SecurityTimestampStringFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffZ";


        public static ACABulkRequestStatusService.ACABulkRequestTransmitterStatusDetailResponseType CheckStatus(string receiptID, string tCCode, string certificatePath, string certificatePassword, string statusServiceUrl)
        {
            //go ahead and generate some of the ids and timestamps we'll need
            var securityTimeStampWsuId = GenerateWsuId("TS");
            var businessHeaderWsuId = GenerateWsuId("id");
            var detailRequestWsuId = GenerateWsuId("id");
            var signatureWsuId = GenerateWsuId("SIG");

            var securityTimestampUTC = DateTime.UtcNow;
            var securityTimestampCreated = securityTimestampUTC.ToString(SecurityTimestampStringFormat);
            var securityTimestampExpires = securityTimestampUTC.AddMinutes(10).ToString(SecurityTimestampStringFormat);

            //build the envelope
            //load the base envelope xml
            var doc = new XmlDocument();
            doc.PreserveWhitespace = false;
            doc.Load("BaseStatusRequestEnvelope.xml");

            /* Need a bunch of namespaces defined
             * xmlns:oas1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
             * xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
             * xmlns:urn="urn:us:gov:treasury:irs:msg:irstransmitterstatusrequest"
             * xmlns:urn1="urn:us:gov:treasury:irs:ext:aca:air:7.0" 
             * xmlns:urn2="urn:us:gov:treasury:irs:common"
             * xmlns:urn3="urn:us:gov:treasury:irs:msg:acasecurityheader"
             * xmlns:wsa="http://www.w3.org/2005/08/addressing"
             * xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
             * xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
             * xmlns:ds="http://www.w3.org/2000/09/xmldsig#");
             */
            XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);
            nsMgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
            nsMgr.AddNamespace("urn", "urn:us:gov:treasury:irs:msg:irstransmitterstatusrequest");
            nsMgr.AddNamespace("urn1", "urn:us:gov:treasury:irs:ext:aca:air:7.0");
            nsMgr.AddNamespace("urn2", "urn:us:gov:treasury:irs:common");
            nsMgr.AddNamespace("urn3", "urn:us:gov:treasury:irs:msg:acasecurityheader");
            nsMgr.AddNamespace("wsa", "http://www.w3.org/2005/08/addressing");
            nsMgr.AddNamespace("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
            nsMgr.AddNamespace("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
            nsMgr.AddNamespace("oas1", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
            nsMgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");

            //start replacing values in it
            //for securityHeader, should have the following
            /*
             * securityHeader.Timestamp.Id
             * securityHeader.Timestamp.Created.Value
             * securityHeader.Timestamp.Expires.Value
             */
            doc.SelectSingleNode("//wsse:Security/wsu:Timestamp", nsMgr).Attributes["wsu:Id"].Value = securityTimeStampWsuId;
            doc.SelectSingleNode("//wsse:Security/wsu:Timestamp/wsu:Created", nsMgr).InnerText = securityTimestampCreated;
            doc.SelectSingleNode("//wsse:Security/wsu:Timestamp/wsu:Expires", nsMgr).InnerText = securityTimestampExpires;

            //for businessHeader, should have the following
            /*
             * businessHeader.UniqueTransmissionId
             * businessHeader.Timestamp
             * businessHeader.Id 
             */
            doc.SelectSingleNode("//urn:ACABusinessHeader", nsMgr).Attributes["wsu:Id"].Value = businessHeaderWsuId;
            doc.SelectSingleNode("//urn:ACABusinessHeader/urn1:UniqueTransmissionId", nsMgr).InnerText = GetUniqueTransmissionId(Guid.NewGuid(), tCCode);
            doc.SelectSingleNode("//urn:ACABusinessHeader/urn2:Timestamp", nsMgr).InnerText = securityTimestampUTC.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ssZ");

            //for ACABulkRequestTransmitterStatusDetailRequest, should have the following
            /*
             * ACABulkRequestTransmitterStatusDetailRequest.Id
             * ACABulkRequestTransmitterStatusDetailRequest.ACABulkReqTrnsmtStsReqGrpDtl.ReceiptId
             */
            doc.SelectSingleNode("//urn:ACABulkRequestTransmitterStatusDetailRequest", nsMgr).Attributes["wsu:Id"].Value = detailRequestWsuId;
            doc.SelectSingleNode("//urn:ACABulkRequestTransmitterStatusDetailRequest/urn1:ACABulkReqTrnsmtStsReqGrpDtl/urn2:ReceiptId", nsMgr).InnerText = receiptID;

            //now do some more security setup
            var cert = new X509Certificate2(certificatePath, certificatePassword, X509KeyStorageFlags.MachineKeySet);

            var exported = cert.Export(X509ContentType.Cert, certificatePassword);
            var base64 = Convert.ToBase64String(exported);

            //now compute all the signing stuff
            var xSigned = new SignedXmlWithId(doc);

            // Add the key to the SignedXml document.
            xSigned.SigningKey = cert.PrivateKey;
            xSigned.Signature.Id = signatureWsuId;
            xSigned.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NWithCommentsTransformUrl;

            var keyInfo = new KeyInfo
            {
                Id = GenerateWsuId("KI")
            };

            //need to get the keyinfo into the signed xml stuff before we compute sigs, and because it is using some stuff that
            //doesn't appear to be supported out of the box we'll work around it by adding a node directly
            var sbKeyInfo = new StringBuilder();
            sbKeyInfo.Append("<root xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">");
            sbKeyInfo.Append("<wsse:SecurityTokenReference wsu:Id=\"" + GenerateWsuId("STR") + "\">");
            sbKeyInfo.Append("<wsse:KeyIdentifier EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\" ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\">" + base64.ToString());
            sbKeyInfo.Append("</wsse:KeyIdentifier>");
            sbKeyInfo.Append("</wsse:SecurityTokenReference>");
            sbKeyInfo.Append("</root>");
            XmlDocument tempDoc = new XmlDocument();
            tempDoc.LoadXml(sbKeyInfo.ToString());

            keyInfo.AddClause(new KeyInfoNode((XmlElement)tempDoc.FirstChild.FirstChild));

            xSigned.KeyInfo = keyInfo;

            GenerateReference(securityTimeStampWsuId, "wsse wsa oas1 soapenv urn urn1 urn2 urn3", xSigned);
            GenerateReference(businessHeaderWsuId, "wsa oas1 soapenv urn1 urn2 urn3", xSigned);
            GenerateReference(detailRequestWsuId, "oas1 soapenv urn1 urn2 urn3", xSigned);

            // Compute the Signature.
            xSigned.ComputeSignature();

            //signing stuff must come before the timestamp or the IRS service complains
            doc.SelectSingleNode("//wsse:Security", nsMgr).InsertBefore(xSigned.GetXml(), doc.SelectSingleNode("//wsse:Security", nsMgr).FirstChild);

            //get the completed envelope
            var envelope = doc.OuterXml;

            //start the webrequest
            //get the request object
            var request = CreateWebRequest(statusServiceUrl);

            //get the request stream and then get a writer on it
            using (var stream = request.GetRequestStream())
            using (var gz = new GZipStream(stream, CompressionMode.Compress))
            using (var writer = new StreamWriter(gz))
            {
                //start by writing the soap envelope to the stream
                writer.WriteLine(envelope);
                writer.Close();
                stream.Close();
            }

            //get the response
            WebResponse response;

            //let an exception get thrown up the stack
            response = request.GetResponse();

            //get the response stream, get a reader on it, and read the response as text
            using (var responseStream = response.GetResponseStream())
            using (var reader = new StreamReader(responseStream, Encoding.UTF8))
            {
                var responseText = reader.ReadToEnd();

                //rip the one element (and children) we need out
                var match = Regex.Match(responseText, @"<(?'prefix'[\w\d]*):ACABulkRequestTransmitterStatusDetailResponse.*<\/\k<prefix>:ACABulkRequestTransmitterStatusDetailResponse>");

                return Deserialize<ACABulkRequestStatusService.ACABulkRequestTransmitterStatusDetailResponseType>(match.ToString());
            }
        }

        private static string GetUniqueTransmissionId(Guid transmissionGuid, string tCCode)
        {
            return string.Format("{0}:SYS12:{1}::T", transmissionGuid, tCCode);
        }

        private static string GenerateWsuId(string prefix)
        {
            return string.Format("{0}-{1}", prefix, Guid.NewGuid().ToString().Replace("-", "").ToUpper());
        }

        private static void GenerateReference(string elementID, string inclusivePrefixList, SignedXmlWithId xSigned)
        {
            var reference = new Reference()
            {
                Uri = "#" + elementID
            };

            XmlDsigExcC14NTransform env = new XmlDsigExcC14NTransform();
            env.InclusiveNamespacesPrefixList = inclusivePrefixList;
            reference.AddTransform(env);

            xSigned.AddReference(reference);
        }

        /// <summary>
        /// creates a webrequest object and prefills some required headers and such
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private static HttpWebRequest CreateWebRequest(string url)
        {
            //setup a web request with all the headers and such that the service requires
            var webRequest = (HttpWebRequest)WebRequest.Create(url);

            webRequest.Method = "POST";
            webRequest.ProtocolVersion = HttpVersion.Version11;
            webRequest.Headers.Add(HttpRequestHeader.ContentEncoding, "gzip");
            webRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
            webRequest.ContentType = "text/xml;charset=UTF-8";
            webRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            webRequest.Headers.Add("SOAPAction", "RequestSubmissionStatusDetail");
            webRequest.KeepAlive = true;

            return webRequest;
        }

        /// <summary>
        /// deserializes the xml string into an object
        /// </summary>
        /// <param name="xmlString"></param>
        /// <returns></returns>
        public static T Deserialize<T>(string xmlString) where T : class
        {
            //if the string is empty, just return null
            if (xmlString.Length <= 0)
            {
                return null;
            }

            //create a serializer
            var serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
            T output;
            //create the reader that the serializer will read from, passing it the string
            using (var reader = new System.IO.StringReader(xmlString))
            {
                //rebuild the list object
                output = (T)serializer.Deserialize(reader);
            }
            //return the list
            return output;
        }
    }
}

関連するベース xml は次のとおりです。

<?xml version="1.0" encoding="utf-8" ?>
<soapenv:Envelope
xmlns:oas1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:us:gov:treasury:irs:msg:irstransmitterstatusrequest"
xmlns:urn1="urn:us:gov:treasury:irs:ext:aca:air:7.0" xmlns:urn2="urn:us:gov:treasury:irs:common"
xmlns:urn3="urn:us:gov:treasury:irs:msg:acasecurityheader">
  <soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <wsu:Timestamp wsu:Id="XXXXXXXXXXXXXXXXXX">
        <wsu:Created>XXXXXXXXXXXXXXXXXX</wsu:Created>
        <wsu:Expires>XXXXXXXXXXXXXXXXXX</wsu:Expires>
      </wsu:Timestamp>
    </wsse:Security>
    <urn:ACABusinessHeader wsu:Id="XXXXXXXXXXXXXXXXXX" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <urn1:UniqueTransmissionId>
        XXXXXXXXXXXXXXXXXX
      </urn1:UniqueTransmissionId>
      <urn2:Timestamp>XXXXXXXXXXXXXXXXXX</urn2:Timestamp>
    </urn:ACABusinessHeader>
    <urn3:ACASecurityHeader />
    <wsa:Action>RequestSubmissionStatusDetail</wsa:Action>
  </soapenv:Header>
  <soapenv:Body>
    <urn:ACABulkRequestTransmitterStatusDetailRequest version="1.0" wsu:Id="XXXXXXXXXXXXXXXXXX" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <urn1:ACABulkReqTrnsmtStsReqGrpDtl>
        <urn2:ReceiptId>XXXXXXXXXXXXXXXXXX</urn2:ReceiptId>
      </urn1:ACABulkReqTrnsmtStsReqGrpDtl>
    </urn:ACABulkRequestTransmitterStatusDetailRequest>
  </soapenv:Body>
</soapenv:Envelope>

この場合、WSDL で生成されたクラスに加える必要があった主な変更は次のとおりです。

    [System.SerializableAttribute()]
    [XmlRoot("ACABulkRequestTransmitterStatusDetailResponse", Namespace = "urn:us:gov:treasury:irs:msg:irstransmitterstatusrequest")]
    public class ACABulkRequestTransmitterStatusDetailResponseType
    {
        private ACABulkRequestTransmitterResponseType aCABulkRequestTransmitterResponseField;
        private ACABulkReqTrnsmtStsRespGrpDtlType aCABulkReqTrnsmtStsRespGrpDtlField;
        private string versionField;
        public ACABulkRequestTransmitterStatusDetailResponseType()
        {
            this.versionField = "1.0";
        }
        [System.Xml.Serialization.XmlElementAttribute(Namespace = "urn:us:gov:treasury:irs:ext:aca:air:7.0", Order = 0)]
        public ACABulkRequestTransmitterResponseType ACABulkRequestTransmitterResponse
        {
            get
            {
                return this.aCABulkRequestTransmitterResponseField;
            }
            set
            {
                this.aCABulkRequestTransmitterResponseField = value;
            }
        }
        [System.Xml.Serialization.XmlElementAttribute(Namespace = "urn:us:gov:treasury:irs:ext:aca:air:7.0", Order = 1)]
        public ACABulkReqTrnsmtStsRespGrpDtlType ACABulkReqTrnsmtStsRespGrpDtl
        {
            get
            {
                return this.aCABulkReqTrnsmtStsRespGrpDtlField;
            }
            set
            {
                this.aCABulkReqTrnsmtStsRespGrpDtlField = value;
            }
        }
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string version
        {
            get
            {
                return this.versionField;
            }
            set
            {
                this.versionField = value;
            }
        }
    }
于 2016-05-24T20:21:46.687 に答える
1

ds プレフィックスを追加すると、実際にこれが壊れています。SignatureValue 要素には、シリアル化された SignedInfo 要素の x509 ハッシュが含まれます (これは、空白の一貫性が重要な場合です)。

SignedInfo 要素を変更すると、IRS が送信した SignatureValue ハッシュと、アップロードして提供された TCC に関連付けられた証明書を使用した SignedInfo ハッシュの計算を比較するときに、認証が失敗します。

SignedInfo 要素の変更を削除するだけで、すべてがうまくいくはずです。わたしにはできる。

于 2016-03-19T19:44:36.633 に答える
0

次のエラーが発生した場合:

AIRMF3002 転送が拒否されました - 添付ファイルのバイト サイズ番号で検証エラーが発生したため、要求を処理できません

IRS 側で、予想されるサイズ (ドキュメンテーションによる) と実際に受け入れられるサイズに問題があるようです。もともと、私は次のコードを持っていました:

// Size in Bytes of File: This code returns the "Size" located on the File's Property Page.
// Result: TRANSMISSION REJECTED ON INCORRECT FILE SIZE!
manifestHeader.AttachmentByteSizeNum = new FileInfo(FormDataFilePath).Length.ToString();

上記のコードを次のコードに置き換えたところ、受け取っていたエラーは解決されました。

// Read the contents of the file, and retrieve the length of the content of the file itself..
// Result: TRANSMISSION WAS ACCEPTED USING THIS FILE SIZE.
manifestHeader.AttachmentByteSizeNum = File.ReadAllText(FormDataFilePath).Length.ToString();

Web サービスは、実際のファイルのサイズではなく、ファイル コンテンツのサイズを実際に予期しているように見えます。テスト シナリオに関連するサイズの違いは、約 3 バイトでした。ファイルのサイズを取得すると、実際のコンテンツに属さないファイル関連の情報が追加されるためだと思います。

IRS のドキュメントに関するこの問題について IRS に通知しました。

于 2016-06-17T20:26:43.323 に答える
0

これは上記の投稿に加えられた編集であり、jstill の投稿にさらに情報が追加されました。残念ながら、査読者はそれを拒否しました。

Reference.csステータスのファイルにまだ加えられている変更に加えて、メソッドを部分的に機能させるために、彼がサブミッションのファイルに加えた更新も含める必要がBulkExchangeFileTypeありました。IncludeFileTypeReference.csDeserializer

このDeserializerメソッドはTransmissionStatusCdと の要素を期待どおりに返しますが、要素を適切ReceiptIdに設定しません。ErrorDataFile

現時点では、ErrorDataFileオブジェクトを適切に設定できないためACABulkRequestTransmitterStatusDetailResponseType、ステータス Web サービスから返された応答を取得するためにオブジェクトを使用していません。ResponseStream代わりに、をオブジェクトに読み込み、応答stringの (最大で) 2 つの部分を解析し、MIME必要に応じてそれらを処理することにしました。


Status の Reference.cs への追加の変更

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34283")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:us:gov:treasury:irs:common")]
public partial class BulkExchangeFileType : object, System.ComponentModel.INotifyPropertyChanged
{
    private IncludeType includeField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElement(Order = 0, Namespace = "http://www.w3.org/2004/08/xop/include")]
    public IncludeType Include
    {
        get { return this.includeField; }
        set
        {
            this.includeField = value;
            this.RaisePropertyChanged("Include");
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    protected void RaisePropertyChanged(string propertyName)
    {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if (propertyChanged != null)
        {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34283")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://www.w3.org/2004/08/xop/include")]
public partial class IncludeType : object, System.ComponentModel.INotifyPropertyChanged
{
    private System.Xml.XmlNode[] anyField;
    private string hrefField;

    /// <remarks/>
    [System.Xml.Serialization.XmlTextAttribute()]
    [System.Xml.Serialization.XmlAnyElementAttribute(Order = 0)]
    public System.Xml.XmlNode[] Any
    {
        get { return this.anyField; }
        set
        {
            this.anyField = value;
            this.RaisePropertyChanged("Any");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute(DataType = "string")]
    public string href
    {
        get { return this.hrefField; }
        set
        {
            this.hrefField = value;
            this.RaisePropertyChanged("href");
        }
    } 

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    protected void RaisePropertyChanged(string propertyName)
    {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if (propertyChanged != null)
        {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}
于 2016-05-31T20:27:55.447 に答える