public void ProcessRequest(HttpContext context)
        {
            var soapAction = context.Request.ContentType; //_requestExtensionMethods.GetSoapAction(context);
            var soapBody   = _requestExtensionMethods.GetSoapBody(context);
            var logSoap    = AppSettings.Get <bool>("LogSoap");

            if (logSoap)
            {
                var nameLoger = "Request_" + DateTime.Now;
                using (var logger = LoggingFactory.GetNLogger(nameLoger))
                {
                    logger.Info(soapBody + "-------soap action ContentType:" + soapAction);
                }
            }
            if (string.IsNullOrEmpty(soapBody))
            {
                context.Response.StatusCode = 400;
                context.Response.End();
            }

            #region Log SOAP Request Message


            if (logSoap)
            {
                var nameLoger = "Request_" + DateTime.Now;
                using (var logger = LoggingFactory.GetNLogger(nameLoger))
                {
                    logger.Info(soapBody);
                }
            }

            #endregion

            //var url = "";
            //var participantCode = _externalCcRequestHelper.GetParticipantCode(soapBody);
            //var exists = _cacheHelper.Exists(participantCode);
            //if (exists)
            //{
            //    url = _cacheHelper.Get<string>(participantCode);
            //}
            //else
            //{
            //    url = _externalCcRequestHelper.GetParticipantUri(participantCode);
            //    _cacheHelper.Add(url, participantCode);
            //}

            MIMBody mimBody = new MIMBody();

            mimBody.Message = soapBody;

            //var test = new ServiceClient();
            //test.InvokeWebMethod(ref mimBody);

            var responseFromExternalCs = "";
            var urlToExternalBus       = AppSettings.Get <string>("UrlToExternalBus");
            //var url = "https://externalcc.interop.st/ExternalCC/Service.svc";
            //var dictionary = new Dictionary<string, string>();
            try
            {
                System.Net.ServicePointManager.ServerCertificateValidationCallback =
                    ((sender, certificate, chain, sslPolicyErrors) => true);//sertifikatot ne im e u red za toa go stavam ova za da go ignorira
                responseFromExternalCs = _externalCcRequestHelper.ResentExternalCCRequest(null, soapBody, urlToExternalBus);
            }
            catch (Exception ex)
            {
                var nameLoger = "Error_" + DateTime.Now;
                using (var logger = LoggingFactory.GetNLogger(nameLoger))
                {
                    logger.Error(ex.Message);
                }
                //_cacheHelper.ClearAll();
                //dictionary = _externalCcRequestHelper.GetAllParticipantsUri();
                //foreach (var participant in dictionary)
                //{
                //    _cacheHelper.Add(participant.Value, participant.Key);
                //}
                //exists = _cacheHelper.Exists(participantCode);
                //if (exists)
                //{
                //    url = _cacheHelper.Get<string>(participantCode);
                //}
                //else
                //{
                //    url = _externalCcRequestHelper.GetParticipantUri(participantCode);
                //    _cacheHelper.Add(url, participantCode);
                //}
                //responseFromExternalCs = _externalCcRequestHelper.ResentExternalCCRequest(soapAction, soapBody, url);
            }


            #region Log SOAP Request Message

            if (logSoap)
            {
                var nameLoger = "Response_" + DateTime.Now;
                using (var logger = LoggingFactory.GetNLogger(nameLoger))
                {
                    logger.Info(responseFromExternalCs);
                }
            }

            #endregion

            var xDoc = XDocument.Parse(responseFromExternalCs);
            //change AdditionalHeader in soapBody
            if (AppSettings.Get <bool>("SwitchAdditionalHeader"))
            {
                XNamespace defaultNs = "http://mioa.gov.mk/interop/mim/v1";
                xDoc.Descendants(defaultNs + "MIMadditionalHeader").Descendants().Remove();
                xDoc.Descendants().SingleOrDefault(x => x.Name.LocalName == "MIMadditionalHeader").Add(new XElement(defaultNs + "Status", ""), new XElement(defaultNs + "StatusMessage", ""), new XElement(defaultNs + "ProviderEndpointUrl", ""), new XElement(defaultNs + "ExternalEndpointUrl", ""), new XElement(defaultNs + "WebServiceUrl", ""), new XElement(defaultNs + "ConsumerBusCode", ""), new XElement(defaultNs + "TimeStampToken", ""), new XElement(defaultNs + "IsInteropTestCommunicationCall", false));
                responseFromExternalCs = xDoc.ToString();

                var nameLoger = "Switch items in additional header" + DateTime.Now;
                using (var logger = LoggingFactory.GetNLogger(nameLoger))
                {
                    logger.Info(responseFromExternalCs);
                }
            }

            HttpContext.Current.Response.ContentType = "application/soap+xml";
            context.Response.Write(responseFromExternalCs);
        }
Ejemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            var logSoap = AppSettings.Get <bool>("LogSoap");

            if (logSoap)
            {
                var nameLoger = "Request to External Handler_" + DateTime.Now;
                using (var logger = LoggingFactory.GetNLogger(nameLoger))
                {
                    logger.Info("---- Request to External Handler ----");
                }
            }


            var  soapBody = string.Empty;
            bool fromFile = bool.Parse(AppSettings.Get <string>("FromFileSystem"));

            if (fromFile)
            {
                soapBody = File.ReadAllText(@"C:\NSRequest.txt");
                var nameLoger = "soapBody_" + DateTime.Now;
                using (var logger = LoggingFactory.GetNLogger(nameLoger))
                {
                    logger.Info(soapBody);
                }
            }
            else
            {
                soapBody = _requestExtensionMethods.GetSoapBody(context);
            }

            if (string.IsNullOrEmpty(soapBody))
            {
                context.Response.StatusCode = 400;

                context.Response.End();
            }

            //var action1 = _requestExtensionMethods.GetSoapAction(context);


            var xDoc        = XDocument.Parse(soapBody);
            var soapAction2 = xDoc.Descendants().SingleOrDefault(x => x.Name.LocalName == "ActionName");


            if (logSoap)
            {
                var nameLoger = "Soap action from SoapBody_" + DateTime.Now;
                using (var logger = LoggingFactory.GetNLogger(nameLoger))
                {
                    logger.Info(soapBody + "------------- soap action from SoapBody:" + soapAction2.Value);
                }
            }



            //var kingExternalBusCode = AppSettings.Get<string>("KingExternalBusCode");
            //var readyMim = _externalCcRequestHelper.UnwrapMimMessage(soapBody, kingExternalBusCode);

            #region Log SOAP Request Message

            if (logSoap)
            {
                var nameLoger = "Request_" + DateTime.Now;
                using (var logger = LoggingFactory.GetNLogger(nameLoger))
                {
                    logger.Info(soapBody);
                }
            }

            #endregion
            List <XNode> childNodes = null;
            //change AdditionalHeader in soapBody
            if (AppSettings.Get <bool>("SwitchAdditionalHeader"))
            {
                XNamespace defaultNs = "http://mioa.gov.mk/interop/mim/v1";
                childNodes = xDoc.Descendants(defaultNs + "MIMadditionalHeader").Nodes().ToList();
                xDoc.Descendants(defaultNs + "MIMadditionalHeader").Descendants().Remove();
                xDoc.Descendants().SingleOrDefault(x => x.Name.LocalName == "MIMadditionalHeader")
                .Add(new XElement(defaultNs + "Status"),
                     new XElement(defaultNs + "StatusMessage"),
                     new XElement(defaultNs + "ProviderEndpointUrl"),
                     new XElement(defaultNs + "ExternalEndpointUrl"),
                     new XElement(defaultNs + "WebServiceUrl"),
                     new XElement(defaultNs + "ConsumerBusCode"),
                     new XElement(defaultNs + "TimeStampToken"),
                     new XElement(defaultNs + "IsInteropTestCommunicationCall", false));
                soapBody = xDoc.ToString();
            }
            else
            {
                XNamespace defaultNs = "http://mioa.gov.mk/interop/mim/v1";
                xDoc.Descendants().SingleOrDefault(x => x.Name.LocalName == "MIMadditionalHeader")
                .Add(new XElement(defaultNs + "TimeStampToken"),
                     new XElement(defaultNs + "IsInteropTestCommunicationCall", false));
                soapBody = xDoc.ToString();
            }
            var nameLoger1 = "Body to be sent to BizTalk_" + DateTime.Now;
            using (var logger = LoggingFactory.GetNLogger(nameLoger1))
            {
                logger.Info("Body to be sent to BizTalk:_____________________" + soapBody);
            }
            var url = AppSettings.Get <string>("UrlToCentralServer");


            string responseFromExternalCs;
            try
            {
                var nameLoger = "soapAction_url_" + DateTime.Now;
                using (var logger = LoggingFactory.GetNLogger(nameLoger))
                {
                    logger.Info("soapAction_url_: " + soapAction2.Value + " " + url);
                }

                responseFromExternalCs = _externalCcRequestHelper.ResentExternalCCRequest(soapAction2.Value, soapBody, url);
            }
            catch (Exception ex)
            {
                var nameLoger = "Error when sent to BizTalk_" + DateTime.Now;
                using (var logger = LoggingFactory.GetNLogger(nameLoger))
                {
                    logger.Info("Error when sent to BizTalk: " + ex);
                }

                throw ex;
            }

            #region Log SOAP Request Message

            if (logSoap)
            {
                var nameLoger = "Response_" + DateTime.Now;
                using (var logger = LoggingFactory.GetNLogger(nameLoger))
                {
                    logger.Info(responseFromExternalCs);
                }
            }

            #endregion

            var xDocAfterResponse = XDocument.Parse(responseFromExternalCs);
            //change back AdditionalHeader in soapBody
            if (AppSettings.Get <bool>("SwitchAdditionalHeader"))
            {
                XNamespace defaultNs = "http://mioa.gov.mk/interop/mim/v1";
                xDocAfterResponse.Descendants(defaultNs + "MIMadditionalHeader").Descendants().Remove();
                foreach (XNode nsNodes in childNodes)
                {
                    xDocAfterResponse.Descendants().SingleOrDefault(x => x.Name.LocalName == "MIMadditionalHeader").Add(nsNodes);
                }

                responseFromExternalCs = xDocAfterResponse.ToString();
            }

            if (logSoap)
            {
                var nameLoger = "Response_to_NS_" + DateTime.Now;
                using (var logger = LoggingFactory.GetNLogger(nameLoger))
                {
                    logger.Info(responseFromExternalCs);
                }
            }

            HttpContext.Current.Response.ContentType = "application/soap+xml";
            context.Response.Write(responseFromExternalCs);
        }