Пример #1
0
        private Identifier getSenderID(OiosiMessage message, DocumentTypeConfig docTypeConfig)
        {
            string senderID = DocumentXPathResolver.GetElementValueByXPathNavigator(
                message.MessageXml,
                docTypeConfig.EndpointType.SenderKey.XPath,
                docTypeConfig.Namespaces);
            var        senderKeyType = Utilities.GetSenderKeyTypeCode(message.MessageXml, docTypeConfig);
            Identifier id            = IdentifierUtility.GetIdentifierFromKeyType(senderID, senderKeyType);

            if (!id.IsAllowedInPublic)
            {
                string cvrNumberString;
                string endpointType;
                if (Credentials.ClientCertificate.TryGetCvrNumberString(out endpointType, out cvrNumberString))
                {
                    id = new Identifier(endpointType, cvrNumberString);
                }
                else
                {
                    throw new Exception("Sender ID is not allowed to be added to header. It was not possible to retrieve ID from certificate");
                }
            }

            return(id);
        }
Пример #2
0
        private static string GetProfileName(OiosiMessage message, DocumentTypeConfig docTypeConfig)
        {
            string profileName = string.Empty;

            // If doctype does't have a XPath expression to extract the document Profile
            // then we assume that the current document type does operate with OIOUBL profiles

            if (docTypeConfig.ProfileIdXPath == null)
            {
                // no profile
            }
            else if (docTypeConfig.ProfileIdXPath.XPath == null)
            {
                // no profile
            }
            else if (string.IsNullOrEmpty(docTypeConfig.ProfileIdXPath.XPath))
            {
                // no profile
            }
            else
            {
                // Fetch the OIOUBL profile name
                string xPath = docTypeConfig.ProfileIdXPath.XPath;
                PrefixedNamespace[] nameSpaces = docTypeConfig.Namespaces;

                profileName = DocumentXPathResolver.GetElementValueByXPathNavigator(message.MessageXml, xPath, nameSpaces);
            }

            return(profileName);
        }
Пример #3
0
        /// <summary>
        /// Discriminates the xml document from a single configuration
        /// element
        /// </summary>
        /// <param name="config"></param>
        /// <param name="xmlDocument"></param>
        /// <param name="namespaces"></param>
        /// <returns></returns>
        public static bool Discriminate(XPathDiscriminatorConfig config, XmlDocument xmlDocument, PrefixedNamespace[] namespaces)
        {
            string xpathExpression = config.XPathExpression;
            string xpathResult     = config.XPathExpectedResult;
            string result          = DocumentXPathResolver.GetElementValueByXPathNavigator(xmlDocument, xpathExpression, namespaces);
            Regex  regex           = new Regex(xpathResult);

            return(regex.IsMatch(result));
        }
Пример #4
0
        /// <summary>
        /// From an xpath expression, gets the endpoint key
        /// </summary>
        /// <param name="xmlDoc">The xml document to search</param>
        /// <param name="xpath">The xpath expression to apply</param>
        /// <param name="keyType">The type of key to return</param>
        /// <param name="prefixedNamespaces">The list of namespaces-prefix pairs used in the xpath expression</param>
        /// <returns>Returns the endpoint key</returns>
        public static Identifier GetEndpointKeyByXpath(
            XmlDocument xmlDoc,
            string xpath,
            PrefixedNamespace[] prefixedNamespaces,
            string keyType
            )
        {
            // 1. Get the endpoint as string:
            string endpointKeyString = DocumentXPathResolver.GetElementValueByXPathNavigator(xmlDoc, xpath, prefixedNamespaces);

            // 2. Convert to the correct IIdentifierType:
            Identifier id = IdentifierUtility.GetIdentifierFromKeyType(endpointKeyString, keyType);

            return(id);
        }
Пример #5
0
        /// <summary>
        /// Gets the endpoint key type code from a Message and a
        /// DocumentTypeConfig.
        /// </summary>
        public static string GetSenderKeyTypeCode(XmlDocument xmlDocument, DocumentTypeConfig documentType)
        {
            //Finds all mapping expressions with the name "EndpointKeyType"
            DocumentEndpointInformation endpointType      = documentType.EndpointType;
            KeyTypeMappingExpression    mappingExpression = endpointType.SenderKey.GetMappingExpression("EndpointKeyType");
            //Finds the endpoint key type value from the given xpath
            string xpathExpression      = mappingExpression.XPathExpression;
            string endPointKeyTypeValue =
                DocumentXPathResolver.GetElementValueByXPathNavigator(
                    xmlDocument,
                    xpathExpression,
                    documentType.Namespaces);
            KeyTypeMapping mapping             = mappingExpression.GetMapping(endPointKeyTypeValue);
            string         endpointKeyTypeCode = mapping.MapsTo;

            return(endpointKeyTypeCode);
        }
Пример #6
0
        protected UddiId GetProfileTModelId(OiosiMessage message, DocumentTypeConfig docTypeConfig)
        {
            UddiId uddiId;

            // If doctype does't have a XPath expression to extract the document Profile
            // then we assume that the current document type does operate with OIOUBL profiles
            if (docTypeConfig.ProfileIdXPath == null)
            {
                uddiId = null;
            }
            else if (docTypeConfig.ProfileIdXPath.XPath == null)
            {
                uddiId = null;
            }
            else if (docTypeConfig.ProfileIdXPath.XPath.Equals(""))
            {
                uddiId = null;
            }
            else
            {
                // Fetch the OIOUBL profile name
                string profileName = DocumentXPathResolver.GetElementValueByXPathNavigator(
                    message.MessageXml,
                    docTypeConfig.ProfileIdXPath.XPath,
                    docTypeConfig.Namespaces);

                ProfileMappingCollectionConfig config = ConfigurationHandler.GetConfigurationSection <ProfileMappingCollectionConfig>();
                if (config.ContainsProfileMappingByName(profileName))
                {
                    ProfileMapping profileMapping    = config.GetMapping(profileName);
                    string         profileTModelGuid = profileMapping.TModelGuid;
                    uddiId = IdentifierUtility.GetUddiIDFromString(profileTModelGuid);
                }
                else
                {
                    throw new Exception("GetProfileTModelId failed for : " + profileName);
                }
            }

            return(uddiId);
        }
Пример #7
0
        /// <summary>
        /// Adds custom RASP headers to a given OiosiMessage
        /// </summary>
        /// <param name="message">The message on which the headers should be added</param>
        /// <param name="documentId">The document Id used in the MessageIdentifier header</param>
        private void AddCustomHeaders(OiosiMessage message, string documentId)
        {
            var typeSearcher = new DocumentTypeConfigSearcher();
            DocumentTypeConfig docTypeConfig = typeSearcher.FindUniqueDocumentType(message.MessageXml);

            // Add custom headers to the message
            Identifier senderIdentifier   = getSenderID(message, docTypeConfig);
            Identifier receiverIdentifier = GetReceiverID(message, docTypeConfig);

            string key = PartyIdentifierHeaderSettings.MessagePropertyKey;
            var    partyIdentifierSetting = new PartyIdentifierHeaderSettings(senderIdentifier, receiverIdentifier);

            message.UbiquitousProperties[key] = partyIdentifierSetting;

            // Adds custom headers by xpaths
            foreach (CustomHeaderXPathConfiguration xpath in docTypeConfig.CustomHeaderConfiguration.XPaths)
            {
                var value         = DocumentXPathResolver.GetElementValueByXPathNavigator(message.MessageXml, xpath.XPath, docTypeConfig.Namespaces);
                var qualifiedName = new XmlQualifiedName(xpath.Name, Definitions.DefaultOiosiNamespace2007);
                message.MessageHeaders[qualifiedName] = MessageHeader.CreateHeader(qualifiedName.Name, qualifiedName.Namespace, value);
            }

            // Add the MessageIdentifier header
            var messageIdentifierHeaderName = new XmlQualifiedName("MessageIdentifier", Definitions.DefaultOiosiNamespace2007);

            message.MessageHeaders[messageIdentifierHeaderName] = MessageHeader.CreateHeader(messageIdentifierHeaderName.Name, messageIdentifierHeaderName.Namespace, documentId);

            // Change the SOAP actions
            if (!string.IsNullOrEmpty(docTypeConfig.EndpointType.RequestAction))
            {
                message.RequestAction = docTypeConfig.EndpointType.RequestAction;
            }
            if (!string.IsNullOrEmpty(docTypeConfig.EndpointType.ReplyAction))
            {
                message.ReplyAction = docTypeConfig.EndpointType.ReplyAction;
            }
        }