Beispiel #1
0
        public void Receive()
        {
            try
            {
                Log.Debug("New Transaction -------------------------------------\n");
                HttpContext context    = HttpContext.Current;
                AS2Receive  as2Receive = new AS2Receive();
                AS2Send     as2Send    = new AS2Send();

                string sTo        = context.Request.Headers["AS2-To"];
                string sFrom      = context.Request.Headers["AS2-From"];
                string sMessageID = context.Request.Headers["Message-ID"];
                Log.Info(context.Request);

                if (context.Request.HttpMethod == "POST" || context.Request.HttpMethod == "PUT" ||
                    (context.Request.HttpMethod == "GET" && context.Request.QueryString.Count > 0))
                {
                    if (sFrom == null || sTo == null)
                    {
                        //Invalid AS2 Request.
                        //Section 6.2 The AS2-To and AS2-From header fields MUST be present in all AS2 messages
                        if (!(context.Request.HttpMethod == "GET" && context.Request.QueryString[0].Length == 0))
                        {
                            AS2Receive.BadRequest(context.Response, "Invalid or unauthorized AS2 request received.");
                        }
                    }
                    else
                    {
                        Log.Debug("Processing EDI transaction -------------------------------------\n");
                        as2Receive.Process(context.Request, WebConfigurationManager.AppSettings["DropLocation"]);
                        // Send ther MDN
                        Log.Debug("Sending MDN back -------------------------------------\n");
                        as2Send.SendMDN(context.Request, 50000, ConfigValues.SigningCertFilename, ConfigValues.SigningCertPassword);
                    }
                }
                else
                {
                    AS2Receive.GetAPIStatusMessage(context.Response);
                }

                context.Response.Write("SUCCESS");
                context.Response.StatusCode        = 200;
                context.Response.StatusDescription = "Successful";
                Log.Debug("Transaction END-------------------------------------\n" +
                          "----------------------------------------------------------------------------------");
            }
            catch (Exception ex)
            {
                Log.ErrorFormat($"Critical error during EDI transaction processing\n" +
                                $"Exception : {ex.Message}\n" +
                                $"Inner Exception : {ex.InnerException?.Message}\n" +
                                $"Stack Trace : \n{ex.StackTrace}\n");
                Log.Error("Transaction FAILED-------------------------------------\n" +
                          "----------------------------------------------------------------------------------");
            }
        }
Beispiel #2
0
        public void SendTestEDIFile()
        {
            try
            {
                Log.Info("Inside Send Method");
                string fileName = "SendFile.txt";

                byte[]        file  = File.ReadAllBytes(string.Format("{0}\\{1}", ConfigValues.PickLocation, fileName));
                ProxySettings proxy = new ProxySettings();

                AS2Send as2Send = new AS2Send();
                as2Send.SendFile(ConfigValues.DestinationUri, fileName, file, ConfigValues.LocalFrom, ConfigValues.LocalTo, proxy, 50000, ConfigValues.SigningCertFilename, ConfigValues.SigningCertPassword,
                                 ConfigValues.RecipientPubCertFilename);
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
        }