This is a C# source code that generates an encrypted AS2 message with a request for an MDN.  The complete program can be downloaded at EDIINT AS2
A detailed explanation of the algorithm can be read at "Creating an AS2 client in stages".


private void btnEncryptMdn_Click(object sender, EventArgs e)
        {
            ediDocument oEdiDoc = null;
            mailDocument oMailDoc = null;
            mailMessage oMailSubject = null;
            bool bSyncronous = true;

            string sPath = AppDomain.CurrentDomain.BaseDirectory;

            oEdiDoc = new ediDocument();

            // Object for AS2 file
            oMailDoc = oEdiDoc.GetMailDocument();

            // Setting so that syntax for the field "Disposition-Notification-To" is not validated, but treated as a free form text field
            oMailDoc.AddDefinedHeader("Disposition-Notification-To", MailMessageHeaderTypeConstants.HeaderType_FieldText, RequirementTypeConstants.Requirement_Optional);

            // Object for subject/content in AS2 file
            oMailSubject = oMailDoc.GetMessageContent();

            // In an encrypted AS2 message, only the "Content-Type" header is encrypted with the content.  So all the other headers have been moved after the Prepare method.

            //add appropriate header to describe the content
            //  - "Application/EDI-X12" for EDI X12
            //  - "Application/EDIFACT" for EDI UN/EDIFACT
            //  - "Application/XML" for XML
            oMailSubject.set_HeaderFieldValue("Content-Type", "Application/EDI-X12");

            //the content to be sent in this AS2 message is an EDI X12 file.  The file is imported into the message object.
            oMailSubject.Import(sPath + "ediFile.X12");

            // Configuration of the security of this message starts by creating the Security object
            ediSecurity oSecurity = oMailSubject.GetSecurity();  

            // Specify the type of encryption and signing algorithm to use in the encrption
            oSecurity.EncryptionAlgorithm = "3DES";
            oSecurity.AssuranceAlgorithm = "SHA-1";

            // Only your trading partner's public key certificate is required to encrypt the message.
            // Recipient's certificate to encrypt message.
            oSecurity.SetCertSubjectNameByLocation("TradingPartner_Cert", "CurrentUser", "My", "Microsoft Strong Cryptographic Provider");
            
            oSecurity.EnableEncryption = true;

            Cursor = Cursors.WaitCursor;

            //Encryption of the current message happens here.
            if (oMailSubject.Prepare() != 1)
            {
                MessageBox.Show("Failed to prepare mail subject");
            }
            else
            {
                //These headers were moved after the Prepare method so that they don't get included in the encrypted message.

                // Put globally unique ID as Message-ID.
                oMailSubject.set_HeaderFieldValue("Message-ID", "1234567890@evalusercompany.com");  //txtMessageID.Text
                // Put AS2 version.
                oMailSubject.set_HeaderFieldValue("AS2-Version", "1.0");
                // Put AS2-To header value.
                oMailSubject.set_HeaderFieldValue("AS2-To", "ToCompanyABC");
                // Put AS2-From header value.
                oMailSubject.set_HeaderFieldValue("AS2-From", "FromCompanyXYZ");

                // MDN can be requested to be sent by the following ways:
                //  - Synchronously - use the same connection to receive the MDN that was used to send the AS2 message. 
                //  - Asynchronously - use a different connection to receive the MDN.  

                if (!bSyncronous) // asyschronous
                {
                    // For asynchronous MDN, you must set a syntactically correct URI to header 'Receipt-delivery-option'.
                    oMailSubject.set_HeaderFieldValue("Receipt-delivery-option", "http://domain.com:9999/testsite/AsyncMDN/");
                }
                else
                {
                    // Request MDN Acknowledgment by adding a "Disposition-Notification-To" header.
                    // Value must be present when requesting for MDN, but holds no meaning in an AS2 environment.
                    oMailSubject.set_HeaderFieldValue("Disposition-Notification-To", "<evaluser@evalusercompany.com>");
                }

                //This is the file that you would send by http or https
                oMailDoc.Save(sPath + @"\MailFolder\AS2EncryptedMdnRequest.bin");

                TransmitFileByHttp(ref oMailDoc, "AS2EncryptedMdnRequest.bin");

                if (bSyncronous) // MDN syschronous
                {
                    mailMessage oMDN = oMailDoc.GetMDN();   // Gets the MDN that was received syncronously
                    oMDN.Save(sPath + @"MailFolder\Received_MDN.bin");  // Saves the MDN to a file
                    ReadMdnMessage(ref oMDN);
                    oMDN.Dispose();
                }
                else // MDN asyschronous
                {
                    mailMessage oMDN = new mailMessage();
                    oMDN.Import(sPath + @"MailFolder\Received_MDN.bin");  //This is the MDN received asyncronously so it needs to be loaded into the oMDN object.
                    ReadMdnMessage(ref oMDN);
                    oMDN.Dispose();
                } // if (bSyncronous)

            }  // if (oMailSubject.Prepare())

            oSecurity.Dispose();
            oMailSubject.Dispose();
            oMailDoc.Dispose();
            oEdiDoc.Dispose();

            Cursor = Cursors.Default;
            MessageBox.Show("Done");

        } 
        

    Click here to evaluate the Framework EDI