예제 #1
0
        //---------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the Acknolwedment AS2 detials
        /// </summary>
        /// <param name="gtinCode">Item GTIN Code</param>
        /// <returns></returns>
        //---------------------------------------------------------------------------------------
        public AS2CommunicationModel GetAS2CommunicationDetials(string identifier)
        {
            DbDataReader          idrOrder         = null;
            AS2CommunicationModel communicationObj = new AS2CommunicationModel();

            try
            {
                List <WebOrderDetailModel> detailList = new List <WebOrderDetailModel>();

                DbInputParameterCollection paramCollection = new DbInputParameterCollection()
                {
                    DbInputParameter.GetInstance("@identifier",
                                                 DbType.String,
                                                 identifier)
                };

                idrOrder = this.DataAcessService.ExecuteQuery(OrderSql["GetAS2CommunicationDetails"], paramCollection);

                if (idrOrder != null && idrOrder.HasRows)
                {
                    while (idrOrder.Read())
                    {
                        communicationObj.AS2Identifier   = ExtensionMethods.GetString(idrOrder, "as2_identifier").ToString();
                        communicationObj.AS2MDNURL       = ExtensionMethods.GetString(idrOrder, "as2_mdn_url").ToString();
                        communicationObj.CertificateName = ExtensionMethods.GetString(idrOrder, "certificate").ToString();
                        communicationObj.CertificateType = ExtensionMethods.GetString(idrOrder, "certificate_type").ToString();
                        communicationObj.MessageFormat   = ExtensionMethods.GetString(idrOrder, "as2_message_format").ToString();
                        communicationObj.PayLoadType     = ExtensionMethods.GetString(idrOrder, "as2_payload_type").ToString();
                    }
                }
                return(communicationObj);
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (idrOrder != null && (!idrOrder.IsClosed))
                {
                    idrOrder.Close();
                }
            }
        }
예제 #2
0
파일: AS2Send.cs 프로젝트: supunt/test_app
        public HttpStatusCode SendMDN(HttpRequest request, int timeoutMs, string signingCertFilename, string signingCertPassword)
        {
            try
            {
                string fileData = "This is an automated MDN";
                byte[] content  = Encoding.ASCII.GetBytes(fileData);


                OrderDataService      OrderDataServ = new OrderDataService();
                AS2CommunicationModel commDetails   = OrderDataServ.GetAS2CommunicationDetials(request.Headers["AS2-From"]);

                //Initialise the request
                HttpWebRequest http = (HttpWebRequest)WebRequest.Create(commDetails.AS2MDNURL);
                string         recipientPubCertFilename = commDetails.CertificateName;

                //Define the standard request objects
                http.Method = "POST";

                http.AllowAutoRedirect = true;

                http.KeepAlive = true;

                http.PreAuthenticate = false; //Means there will be two requests sent if Authentication required.
                http.SendChunked     = false;

                //http.UserAgent = "PEERCORE AGENT";

                //These Headers are common to all transactions
                http.Headers.Add("Mime-Version", "1.0");
                http.Headers.Add("AS2-Version", "1.2");
                //http.Headers.Add("Date", DateTime.Now.ToString());

                http.Headers.Add("AS2-From", request.Headers["AS2-To"]);
                http.Headers.Add("AS2-To", request.Headers["AS2-From"]);
                http.Headers.Add("Subject", "PO MDN");
                http.Headers.Add("Message-Id", request.Headers["Message-Id"] != null? request.Headers["Message-Id"]:"0");
                http.Timeout = timeoutMs;

                string contentType = "message/disposition-notification";

                bool encrypt = !string.IsNullOrEmpty(recipientPubCertFilename);
                bool sign    = !string.IsNullOrEmpty(signingCertFilename);

                if (!sign && !encrypt)
                {
                    http.Headers.Add("Content-Transfer-Encoding", "binary");
                    http.Headers.Add("Content-Disposition", "inline");
                }
                if (sign)
                {
                    // Wrap the file data with a mime header
                    content = AS2MIMEUtilities.CreateMessage(contentType, "binary", "", content);

                    content = AS2MIMEUtilities.Sign(content, signingCertFilename, signingCertPassword, out contentType);

                    http.Headers.Add("EDIINT-Features", "multiple-attachments");
                }
                if (encrypt)
                {
                    string certificateFullPath = "";
                    if (string.IsNullOrEmpty(recipientPubCertFilename))
                    {
                        throw new ArgumentNullException(recipientPubCertFilename, "if encrytionAlgorithm is specified then recipientCertFilename must be specified");
                    }
                    else
                    {
                        certificateFullPath = ConfigValues.CertificateFilePath + recipientPubCertFilename;
                    }

                    byte[] signedContentTypeHeader           = System.Text.ASCIIEncoding.ASCII.GetBytes("Content-Type: " + contentType + Environment.NewLine);
                    byte[] contentWithContentTypeHeaderAdded = AS2MIMEUtilities.ConcatBytes(signedContentTypeHeader, content);

                    string ba2Str = System.Text.Encoding.Default.GetString(content);
                    string s1     = System.Text.Encoding.Default.GetString(signedContentTypeHeader);
                    string s2     = System.Text.Encoding.Default.GetString(contentWithContentTypeHeaderAdded);
                    content = AS2Encryption.EncryptMDN(contentWithContentTypeHeaderAdded, certificateFullPath, EncryptionAlgorithm.DES3);

                    //  contentType += "multipart/report; report-type=disposition-notification; boundary=\"fredi.boundary.mult.sig.mdn\"; charset=utf-8";
                }

                http.ContentType  += contentType;
                http.ContentLength = content.Length;

                SendWebRequest(http, content);

                return(HandleWebResponse(http));
            }
            catch (Exception ex)
            {
                Log.Error($"Exception during sending MDN :: {ex.Message}");
                throw;
            }
        }
예제 #3
0
파일: AS2Send.cs 프로젝트: supunt/test_app
        public HttpStatusCode SendAcknowledgment(byte[] fileData, string from, string to, ProxySettings proxySettings
                                                 , int timeoutMs, string signingCertFilename, string signingCertPassword)
        {
            try
            {
                byte[] content = fileData;


                OrderDataService      OrderDataServ = new OrderDataService();
                AS2CommunicationModel commDetails   = OrderDataServ.GetAS2CommunicationDetials(to);

                //  if (commDetails != null)
                //  {

                //Initialise the request
                HttpWebRequest http = (HttpWebRequest)WebRequest.Create(commDetails.AS2MDNURL);
                string         recipientPubCertFilename = commDetails.CertificateName;

                if (!String.IsNullOrEmpty(proxySettings.Name))
                {
                    WebProxy proxy = new WebProxy(proxySettings.Name);

                    NetworkCredential proxyCredential = new NetworkCredential();
                    proxyCredential.Domain   = proxySettings.Domain;
                    proxyCredential.UserName = proxySettings.Username;
                    proxyCredential.Password = proxySettings.Password;

                    proxy.Credentials = proxyCredential;

                    http.Proxy = proxy;
                }

                //Define the standard request objects
                http.Method = "POST";

                http.AllowAutoRedirect = true;

                http.KeepAlive = true;

                http.PreAuthenticate = false; //Means there will be two requests sent if Authentication required.
                http.SendChunked     = false;

                http.UserAgent = "PEERCORE AGENT";

                //These Headers are common to all transactions
                http.Headers.Add("Mime-Version", "1.0");
                http.Headers.Add("AS2-Version", "1.2");

                http.Headers.Add("AS2-From", from);
                http.Headers.Add("AS2-To", to);
                http.Headers.Add("Subject", "PO Acknowledgment");
                http.Headers.Add("Message-Id", "<AS2_" + DateTime.Now.ToString("hhmmssddd") + ">");
                http.Timeout = timeoutMs;

                string contentType = "application/EDIFACT";

                bool encrypt = !string.IsNullOrEmpty(recipientPubCertFilename);
                bool sign    = !string.IsNullOrEmpty(signingCertFilename);

                if (!sign && !encrypt)
                {
                    http.Headers.Add("Content-Transfer-Encoding", "binary");
                    http.Headers.Add("Content-Disposition", "inline");
                }
                if (sign)
                {
                    // Wrap the file data with a mime header
                    content = AS2MIMEUtilities.CreateMessage(contentType, "binary", "", content);

                    content = AS2MIMEUtilities.Sign(content, signingCertFilename, signingCertPassword, out contentType);

                    http.Headers.Add("EDIINT-Features", "multiple-attachments");
                }
                if (encrypt)
                {
                    if (string.IsNullOrEmpty(recipientPubCertFilename))
                    {
                        throw new ArgumentNullException(recipientPubCertFilename, "if encrytionAlgorithm is specified then recipientCertFilename must be specified");
                    }

                    byte[] signedContentTypeHeader           = System.Text.ASCIIEncoding.ASCII.GetBytes("Content-Type: " + contentType + Environment.NewLine);
                    byte[] contentWithContentTypeHeaderAdded = AS2MIMEUtilities.ConcatBytes(signedContentTypeHeader, content);

                    string ba2Str = System.Text.Encoding.Default.GetString(content);
                    string s1     = System.Text.Encoding.Default.GetString(signedContentTypeHeader);
                    string s2     = System.Text.Encoding.Default.GetString(contentWithContentTypeHeaderAdded);
                    content = AS2Encryption.Encrypt(contentWithContentTypeHeaderAdded, recipientPubCertFilename, EncryptionAlgorithm.DES3);


                    if (commDetails.MessageFormat == "SMIME")
                    {
                        contentType += "application/pkcs7-mime; smime-type=enveloped-data; name=\"smime.p7m\"";
                    }
                }

                http.ContentType  += contentType;
                http.ContentLength = content.Length;

                SendWebRequest(http, content);

                return(HandleWebResponse(http));
            }
            catch (Exception ex)
            {
                throw;
            }
        }