Ejemplo n.º 1
0
        public string DistributeSecureV3(SignedDelivery1 message, Guid requestId)
        {
            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.Package.DataLayer.Service: incoming DistributeSecureV3 with RequestId: {0}", requestId));

            MessagePortv3Client client = null;
            string result = string.Empty;

            try
            {
                client = new MessagePortv3Client("MessagePortV3");
                //Call method.
                result = client.distributeSecure(message);
            }
            catch (Exception ex)
            {
                string errorMessage = string.Format("SE.GOV.MM.Integration.Package.Service.MessageService: Exception have been thrown when calling servicemethod DistributeSecureV3. Recipient: {0}, RequestId: {1}", message.Delivery.Header.Recipient, requestId);
                LogManager.Log(new Log.Log()
                {
                    Message = errorMessage, EventId = EventId.CommunicationExceptionWithMessage, Exception = ex, Level = Level.Error
                });
                throw ex;
            }
            finally
            {
                if (client != null && client.State == CommunicationState.Faulted)
                {
                    client.Abort();
                    client.Close();
                }
                client = null;
            }
            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.Package.DataLayer.Service: leaving DistributeSecureV3 with RequestId: {0}", requestId));
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Serialize a SignedDelivery object to a XmlDocument. using defaultnamespace, that is a property from config file, add this to xmlserializer.
        /// </summary>
        public XmlDocument SerializeToXmlDocumentV3(SignedDelivery1 signedDelivery, string defaultNameSpace, Guid requestId)
        {
            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.Package.BusinessLayer.Helper.SerializeHelper: incoming SerializeToXmlDocumentV3 with RequestId: {0}", requestId));

            var xmlDocument = new XmlDocument();

            xmlDocument.PreserveWhitespace = false;

            var xmlSerializerNameSpace = new XmlSerializerNamespaces();

            xmlSerializerNameSpace.Add("", defaultNameSpace);

            using (var memoryStream = new MemoryStream())
            {
                var xmlWriterSettings = new XmlWriterSettings();
                xmlWriterSettings.OmitXmlDeclaration = true;
                xmlWriterSettings.Encoding           = Encoding.UTF8;

                using (var xmlWriter = XmlWriter.Create(memoryStream, xmlWriterSettings))
                {
                    var xmlSerializer = new XmlSerializer(typeof(SignedDelivery1), defaultNameSpace);
                    xmlSerializer.Serialize(xmlWriter, signedDelivery, xmlSerializerNameSpace);
                }

                memoryStream.Position = 0;
                xmlDocument.Load(memoryStream);
            }

            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.Package.BusinessLayer.Helper.SerializeHelper: leaving SerializeToXmlDocumentV3 with RequestId: {0}", requestId));
            return(xmlDocument);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Send a message.
        /// </summary>
        public string SendPackageV3(SignedDelivery1 signedDelivery, Guid requestId)
        {
            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.Package.DataLayer.DataManager: incoming SendPackageV3 with RequestId: {0}", requestId));

            var service = new MessageService();
            var id      = service.DistributeSecureV3(signedDelivery, requestId);

            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.Package.DataLayer.DataManager: leaving SendPackageV3 with RequestId: {0}", requestId));
            return(id);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handler that creates a SignedDelivery from a SecureDelivery.
        /// </summary>
        public SignedDelivery1 GetSignedDeliveryV3(SecureDelivery1 secureDelivery, bool signDelivery, string defaultNameSpace, string signingCertificateSubjectName, Guid requestId)
        {
            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.Package.BusinessLayer.Handler.SignedDeliveryHandler: incoming GetSignedDeliveryV3 with RequestId: {0}", requestId));

            var sDelivery = new SignedDelivery1();

            sDelivery.Delivery = secureDelivery;

            //Check configfile to see if we should sign delivery.
            if (signDelivery)
            {
                try
                {
                    // Serialize SignedDelivery to XmlDocument
                    var serializeHelper = new SerializeHelper();
                    var xmlDocument     = serializeHelper.SerializeToXmlDocumentV3(sDelivery, defaultNameSpace, requestId);

                    // Get signing certificate helper
                    var signingCertificateHelper = new SigningCertificateHelper();
                    var signXmlDocumentHandler   = new SignXmlDocumentHandler();

                    // Sign xml document with certificate
                    var certificate       = signingCertificateHelper.GetXMLSigningCertificate(signingCertificateSubjectName, requestId);
                    var signedXmlDocument = signXmlDocumentHandler.SignXmlDocument(xmlDocument, certificate, requestId);

                    // Deserialize signed xml document to SignedDelivery
                    sDelivery = serializeHelper.DeserializeXmlToSignedDeliveryV3(signedXmlDocument, defaultNameSpace, requestId);
                }
                catch (CryptographicException ce)
                {
                    string errorMessage = string.Format("SE.GOV.MM.Integration.Package.BusinessLayer.Handler: Certification error. RequestId: {0}. ExceptionMessage: {1}", requestId, ce.Message);
                    LogManager.Log(new Log.Log()
                    {
                        Exception = ce, Message = errorMessage, EventId = EventId.XmlDocumentSigningException, Level = Level.Error
                    });
                    throw new Exception(errorMessage);
                }
                catch (Exception e)
                {
                    string errorMessage = string.Format("SE.GOV.MM.Integration.Package.BusinessLayer.Handler: Exception have been thrown. RequestId: {0}. ExceptionMessage: {1}", requestId, e.Message);
                    LogManager.Log(new Log.Log()
                    {
                        EventId = EventId.GenerelizedException, Exception = e, Level = Level.Error, Message = errorMessage
                    });
                    throw e;
                }
            }

            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.Package.BusinessLayer.Handler.SignedDeliveryHandler: leaving GetSignedDeliveryV3 with RequestId: {0}", requestId));
            return(sDelivery);
        }