private string RecreateWsdl(string originalWsdl, string[] methodsNames) { try { XDocument doc = XDocument.Parse(originalWsdl); if (doc.Root != null) { //message part doc = RecreateWsdlMessagePart(doc, methodsNames); //port part doc = RecreateWsdlPortTypePart(doc, methodsNames); //binding part doc = RecreateWsdlBindingPart(doc, methodsNames); } return(doc.ToString()); } catch (Exception ex) { var nameLogerError = "RecreateWSDL_ " + DateTime.Now; using (var logger = LoggingFactory.GetNLogger(nameLogerError)) { logger.Info("There is some error when trying to recreate WSDL. Original wsdl is: " + originalWsdl); } return(originalWsdl); } }
public string ResentExternalCCRequest(string soapAction, string soapBody, string url) { var urlToCentralServer = url; HttpWebRequest request = CreateWebRequest(soapAction, urlToCentralServer); XmlDocument soapEnvelopeXml = new XmlDocument(); soapEnvelopeXml.LoadXml(soapBody); var nameLoger = "soapEnvelopeXml_" + DateTime.Now; using (var logger = LoggingFactory.GetNLogger(nameLoger)) { logger.Info(soapEnvelopeXml.InnerText); logger.Info(soapEnvelopeXml.InnerXml); logger.Info(soapEnvelopeXml.OuterXml); } //MNOGU BITNO, NE TRGAJ ZA DA POMINE NA BIZTALK, PROBLEM KAKO NA http://stackoverflow.com/questions/19258810/xmldocument-save-adds-return-carriages-to-xml-when-elements-are-blank var settings = new XmlWriterSettings { Indent = true }; XmlWriter writer = XmlWriter.Create(request.GetRequestStream(), settings); //using (Stream stream = request.GetRequestStream()) //{ soapEnvelopeXml.Save(writer); //} using (WebResponse response = request.GetResponse()) { using (StreamReader rd = new StreamReader(stream: response.GetResponseStream())) { return(rd.ReadToEnd()); } } }
public void InsertService(IServiceRepository serviceRepository, IParticipantRepository participantRepository, CSService cSservice) { //Downloading the WSDL form WSDL URL taken form CC Register Service //string wsdlURL = null; //if (cSservice.Wsdl.EndsWith("?wsdl")) // wsdlURL = cSservice.Wsdl.Replace("?wsdl", "?singlewsdl"); //string wsdl = null; //using (var wc = new WebClient()) //{ // using (var stream = wc.OpenRead(wsdlURL)) // { // using (var sr = new StreamReader(stream)) // { // wsdl = sr.ReadToEnd(); // } // } //} var participantExist = participantRepository.GetParticipants().Any(x => x.Code == cSservice.ParticipantCode); if (participantExist) { var service = new CSService { ParticipantCode = cSservice.ParticipantCode, Code = cSservice.Code, Name = cSservice.Name, Wsdl = cSservice.Wsdl }; try { serviceRepository.CreateService(service); } catch (Exception e) { var nameLogerError = service.Name + "_ " + DateTime.Now; using (var logger = LoggingFactory.GetNLogger(nameLogerError)) { logger.Error(JsonConvert.SerializeObject(service), e); } throw new FaultException(e.Message); } } else { throw new FaultException("Не постои учесник со име: " + cSservice.ParticipantCode); } }
public SoapMessage SentMimMessage(SoapMessage mimMessage, string action) { #region Log SOAP Request Message var logSoap = AppSettings.Get <bool>("LogSoap"); if (logSoap) { var nameLogerError = "Request_" + DateTime.Now; using (var logger = LoggingFactory.GetNLogger(nameLogerError)) { logger.Info(mimMessage.Body.MimBody.Message.ToString()); } } #endregion #region Log MIM Message MimMsgHelper.LogMimMessage(mimMessage); #endregion //var urlToHostedApp = RequestHelper.GetServiceUrl(mimMessage.Header); var urlToHostedApp = ""; string mimeType; var response = SoapRequestHelper.Execute(mimMessage.Body.MimBody.Message.ToString(), action, urlToHostedApp, out mimeType); var mimMsgResponse = MimMsgHelper.CreateMimResponseMsg(mimMessage, response, mimeType, mimMessage.Header.CryptoHeader.Key, mimMessage.Header.CryptoHeader.InitializationVector); #region Log MIM Message MimMsgHelper.LogMimMessage(mimMsgResponse); #endregion #region Log SOAP Response Message if (logSoap) { var nameLogerError = "Response_" + DateTime.Now; using (var logger = LoggingFactory.GetNLogger(nameLogerError)) { logger.Info(mimMsgResponse.Body.MimBody.Message.ToString()); } } #endregion return(mimMsgResponse); }
public List <ProviderCSDTO> GetProviders(IAccessMappingRepository accessMappingRepository, IParticipantRepository participantRepository, IBusesRepository busesRepository, string consumerId) { var nameLogerError1 = "GetProviders" + "_ " + DateTime.Now; using (var logger = LoggingFactory.GetNLogger(nameLogerError1)) { logger.Info("dosol vo get providers za " + consumerId); } List <ProviderCSDTO> output; try { var accessMappings = accessMappingRepository.GetAccessMappings().Where(x => x.ConsumerCode == consumerId); var participants = participantRepository.GetParticipants(); var accessMappingList = new List <AccessMapping>(); foreach (var am in accessMappings) { var amm = new AccessMapping() { ProviderCode = am.ProviderCode, ProviderBusCode = am.ProviderBusCode, ConsumerCode = am.ConsumerCode }; amm.ProviderCode = amm.ProviderBusCode + "$$" + amm.ProviderCode; accessMappingList.Add(amm); } var accessMappet = accessMappingList.Select(s => s.ProviderCode).Distinct(); var joinedAccessMappingsAndParticipants = accessMappet.Join(participants, am => am, p => p.Code, (am, p) => new ProviderCSDTO { Code = am, PublicKey = p.PublicKey, Name = p.Name }).ToList(); output = joinedAccessMappingsAndParticipants.ToList(); //foreach (var k in accessMapBusExt) //{ // var busURL = k.Url; // //the call is made with MIM1$$consumerId // // get lists from other busses and add them to output //} // } //else //{//call from external BUS, to be tested // string[] stringSeparators = new string[] { "$$" }; // string[] result; // result = consumerId.Split(stringSeparators, StringSplitOptions.None); // var busC = result[0]; // var consumer = result[1]; // var accessMappings = accessMappingRepository.GetAccessMappings().Where(x => x.ConsumerCode == consumer); // var accessMapBus = accessMappings.Where(x => x.ProviderBusCode == ourBus && x.ConsumerBusCode == busC); // var accessMappet = accessMapBus.Select(s => s.ProviderCode).Distinct(); // var participants = participantRepository.GetParticipants(); // var joinedAccessMappingsAndParticipants = accessMappet.Join(participants, am => am, // p => p.Code, (am, p) => new ProviderCSDTO { Code = ourBus + "$$" + am, PublicKey = p.PublicKey }).ToList(); // output = joinedAccessMappingsAndParticipants.ToList(); //} } catch (Exception ex) { var nameLogerError = "GetProviders" + "_ " + DateTime.Now; using (var logger = LoggingFactory.GetNLogger(nameLogerError)) { logger.Info("consumerId = " + consumerId); } throw new FaultException(ex.Message); } return(output); }
public string GetService(IAccessMappingRepository accessMappingRepository, IServiceRepository serviceRepository, IBusesRepository busesRepository, string providerId, string consumerId, string serviceId) { //var ourBus = AppSettings.Get<string>("Bus"); //string[] stringSeparators = new string[] { "$$" }; //string[] result; var map = accessMappingRepository.GetAccessMappings().ToList(); var busP = ""; var provider = ""; //if (providerId.Contains("$$")) //{ string[] stringSeparators = new string[] { "$$" }; string[] result; result = providerId.Split(stringSeparators, StringSplitOptions.None); busP = result[0]; provider = result[1]; //} //if (String.IsNullOrEmpty(busP)) // busP = ourBus; //if (String.IsNullOrEmpty(provider)) //provider = providerId; //if (!providerId.Contains("$$") && !consumerId.Contains("$$")) //{ //var allAvilableServices = map.Where(x => x.ConsumerCode == consumerId && x.ConsumerBusCode == ourBus && x.ProviderCode == providerId && x.ProviderBusCode == ourBus && x.ServiceCode == serviceId); var allAvilableServices = map.Where(x => x.ConsumerCode == consumerId && x.ProviderCode == provider && x.ProviderBusCode == busP && x.ServiceCode == serviceId && x.IsActive); var serviceMethodsFromAvilableServices = allAvilableServices.Select(service => service.MethodCode).ToArray(); if (allAvilableServices.Any()) { //var temp = serviceRepository.GetServices(); //foreach (var ser in temp) //{ // if (ser.ParticipantCode.Contains("$$")) // { // string[] stringSeparators = new string[] { "$$" }; // string[] result; // result = ser.ParticipantCode.Split(stringSeparators, StringSplitOptions.None); // ser.ParticipantCode = result[1]; // } //} //var temp1 = temp.FirstOrDefault(x => x.ParticipantCode == providerId && x.Code == serviceId); var originalWsdl = serviceRepository.GetServices().FirstOrDefault(x => x.ParticipantCode == providerId && x.Code == serviceId).Wsdl; if (serviceMethodsFromAvilableServices.Any()) { return(RecreateWsdl(originalWsdl, serviceMethodsFromAvilableServices)); } } //} //else if (providerId.Contains("$$")) //{ // result = providerId.Split(stringSeparators, StringSplitOptions.None); // var busC = result[0]; // var busURL = busesRepository.GetBuses().Where(x => x.Code == busC).Select(x => x.Url); // // Make call to external Bus with parametars GetService(ourBus$$consumerId, providerId, ServY) // // get list of strings from the external call // return ""; //} //else if (providerId.Contains("$$") && consumerId.Contains("$$")) //{//call from external BUS, to be tested // result = providerId.Split(stringSeparators, StringSplitOptions.None); // var provId = result[1]; // result = consumerId.Split(stringSeparators, StringSplitOptions.None); // var consId = result[1]; // var consBus = result[0]; // var allAvilableServices = map.Where(x => x.ConsumerCode == consId && x.ConsumerBusCode == consBus && x.ProviderCode == provId && x.ProviderBusCode == ourBus && x.ServiceCode == serviceId); // var serviceMethodsFromAvilableServices = allAvilableServices.Select(service => service.MethodCode).ToArray(); // if (allAvilableServices.Any()) // { // var originalWsdl = serviceRepository.GetServices().FirstOrDefault(x => x.ParticipantCode == provId && x.Code == serviceId).Wsdl; // if (serviceMethodsFromAvilableServices.Any()) // { // return RecreateWsdl(originalWsdl, serviceMethodsFromAvilableServices); // } // } //} var nameLogerError = "GetService_ " + DateTime.Now; using (var logger = LoggingFactory.GetNLogger(nameLogerError)) { logger.Info("There is no access maping for that provider and consumer"); } throw new FaultException("There is no access maping for that provider and consumer"); }
public List <SelectListItem> GetServices(IAccessMappingRepository accessMappingRepository, IBusesRepository busesRepository, IServiceRepository servicesRepository, string providerId, string consumerId) { //var ourBus = AppSettings.Get<string>("Bus"); //string[] stringSeparators = new string[] { "$$" }; //string[] result; var nameLogerError = "Vlezni parametri na GetServices" + "_ " + DateTime.Now; using (var logger = LoggingFactory.GetNLogger(nameLogerError)) { logger.Info("provider: " + providerId + "; consumer: " + consumerId); } var output = new List <string>(); var busP = ""; //if (providerId.Contains("$$")) //{ string[] stringSeparators = new string[] { "$$" }; string[] result; result = providerId.Split(stringSeparators, StringSplitOptions.None); busP = result[0]; providerId = result[1]; //} //if (String.IsNullOrEmpty(busP)) //busP = ourBus; using (var logger = LoggingFactory.GetNLogger(nameLogerError)) { logger.Info("busP: " + busP + "; providerId: " + providerId); } output = accessMappingRepository.GetAccessMappings().Where(x => x.ConsumerCode == consumerId && x.ProviderCode == providerId && x.ProviderBusCode == busP && x.IsActive).Select(x => x.ServiceCode).Distinct().ToList(); using (var logger = LoggingFactory.GetNLogger(nameLogerError)) { logger.Info("output: " + output.Count); } var allservices = servicesRepository.GetServices(); var newOutput = new List <SelectListItem>(); foreach (var service in allservices) { if (output.Contains(service.Code)) { var item = new SelectListItem(); item.Value = service.Code; item.Text = service.Name; newOutput.Add(item); } } //if(!providerId.Contains("$$") && !consumerId.Contains("$$")) //{ // output = accessMappingRepository.GetAccessMappings().Where(x => x.ConsumerCode == consumerId && x.ProviderCode == providerId && x.ProviderBusCode == ourBus).Select(x => x.ServiceCode).Distinct().ToList(); //} //else if(providerId.Contains("$$")) //{ //result = providerId.Split(stringSeparators, StringSplitOptions.None); //var busC = result[0]; //var busURL = busesRepository.GetBuses().Where(x => x.Code == busC).Select(x => x.Url); // Make call to external Bus with parametars GetServices(ourBus$$consumerId, providerId) // get list of strings from the external call //} //else if(providerId.Contains("$$") && consumerId.Contains("$$")) //{//call from external BUS, to be tested // result = providerId.Split(stringSeparators, StringSplitOptions.None); // var provId = result[1]; // result = consumerId.Split(stringSeparators, StringSplitOptions.None); // var consId = result[1]; // var consBus = result[0]; // output = accessMappingRepository.GetAccessMappings().Where(x => x.ConsumerCode == consId && x.ConsumerBusCode == consBus && x.ProviderCode == provId && x.ProviderBusCode == ourBus).Select(x => x.ServiceCode).Distinct().ToList(); //} return(newOutput); }
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); }
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); }