コード例 #1
0
        /// <summary>
        /// Create behavior
        /// </summary>
        private void CreateWcfBehaviorConfiguration(string behaviorName, MARC.HI.EHRS.CR.Notification.PixPdq.Configuration.UI.pnlNotification.TargetConfigurationInformation configInfo, XmlElement wcfNode)
        {
            XmlDocument configurationDom = wcfNode.OwnerDocument;
            XmlElement  wcfBehaviorNode  = wcfNode.SelectSingleNode("./*[local-name() = 'behaviors']") as XmlElement;

            if (wcfBehaviorNode == null)
            {
                wcfBehaviorNode = wcfNode.AppendChild(configurationDom.CreateElement("behaviors")) as XmlElement;
            }

            XmlElement wcfServiceBehaviorNode = wcfBehaviorNode.SelectSingleNode("./*[local-name() = 'endpointBehaviors']") as XmlElement;

            if (wcfServiceBehaviorNode == null)
            {
                wcfServiceBehaviorNode = wcfBehaviorNode.AppendChild(configurationDom.CreateElement("endpointBehaviors")) as XmlElement;
            }

            XmlElement wcfRevisionBehaviorNode = wcfServiceBehaviorNode.SelectSingleNode(String.Format("./*[local-name() = 'behavior'][@name = '{0}']", behaviorName)) as XmlElement;

            if (wcfRevisionBehaviorNode == null)
            {
                wcfRevisionBehaviorNode = wcfServiceBehaviorNode.AppendChild(configurationDom.CreateElement("behavior")) as XmlElement;
                wcfRevisionBehaviorNode.Attributes.Append(configurationDom.CreateAttribute("name")).Value = behaviorName;
            }

            // Security?
            XmlElement wcfClientCredentialsNode = wcfRevisionBehaviorNode.SelectSingleNode("./*[local-name() = 'clientCredentials']") as XmlElement;

            if (configInfo.ClientCertificate != null) // Security is enabled
            {
                if (wcfClientCredentialsNode == null)
                {
                    wcfClientCredentialsNode = wcfRevisionBehaviorNode.AppendChild(configurationDom.CreateElement("clientCredentials")) as XmlElement;
                }
                wcfClientCredentialsNode.RemoveAll();

                XmlElement wcfServiceCertificateNode = wcfClientCredentialsNode.AppendChild(configurationDom.CreateElement("clientCertificate")) as XmlElement;
                wcfServiceCertificateNode.Attributes.Append(configurationDom.CreateAttribute("storeLocation")).Value = configInfo.ClientCertificateLocation.ToString();
                wcfServiceCertificateNode.Attributes.Append(configurationDom.CreateAttribute("storeName")).Value     = configInfo.ClientCertificateStore.ToString();
                wcfServiceCertificateNode.Attributes.Append(configurationDom.CreateAttribute("x509FindType")).Value  = X509FindType.FindByThumbprint.ToString();
                wcfServiceCertificateNode.Attributes.Append(configurationDom.CreateAttribute("findValue")).Value     = configInfo.ClientCertificate.Thumbprint;

                // Validate server ?
                if (configInfo.ValidateServerCert)
                {
                    XmlElement clientCertNode = wcfClientCredentialsNode.AppendChild(configurationDom.CreateElement("serviceCertificate")) as XmlElement,
                               authNode       = clientCertNode.AppendChild(configurationDom.CreateElement("authentication")) as XmlElement;
                    authNode.Attributes.Append(configurationDom.CreateAttribute("certificateValidationMode"));
                    authNode.Attributes["certificateValidationMode"].Value = "Custom";
                    authNode.Attributes.Append(configurationDom.CreateAttribute("customCertificateValidatorType"));
                    authNode.Attributes["customCertificateValidatorType"].Value = typeof(SecureNodeCertificateValidator).AssemblyQualifiedName;
                }
            }
            else if (wcfClientCredentialsNode != null) // Remove the credentials node
            {
                wcfRevisionBehaviorNode.RemoveChild(wcfClientCredentialsNode);
            }
        }
コード例 #2
0
        /// <summary>
        /// Binding Configuration
        /// </summary>
        private void CreateWcfBindingConfiguration(string bindingName, MARC.HI.EHRS.CR.Notification.PixPdq.Configuration.UI.pnlNotification.TargetConfigurationInformation configInfo, XmlElement wcfNode)
        {
            XmlDocument configurationDom = wcfNode.OwnerDocument;
            XmlElement  wcfBindingNode   = wcfNode.SelectSingleNode("./*[local-name() = 'bindings']") as XmlElement;

            if (wcfBindingNode == null)
            {
                wcfBindingNode = wcfNode.AppendChild(configurationDom.CreateElement("bindings")) as XmlElement;
            }

            // Get the binding name
            var bindingType = wcfNode.SelectSingleNode(string.Format(".//*[local-name() = 'client']//*[local-name() = 'endpoint'][@bindingConfiguration = '{0}']/@binding", bindingName));

            if (bindingType == null)
            {
                throw new ConfigurationErrorsException("Cannot determine the binding for the specified configuration, does the endpoint have the binding attribute?");
            }

            XmlElement wcfBindingTypeNode = wcfBindingNode.SelectSingleNode(String.Format("./*[local-name() = '{0}']", bindingType.Value)) as XmlElement;

            if (wcfBindingTypeNode == null)
            {
                wcfBindingTypeNode = wcfBindingNode.AppendChild(configurationDom.CreateElement(bindingType.Value)) as XmlElement;
            }

            // Is there a binding with our name on it?
            XmlElement wcfBindingConfigurationNode = wcfBindingTypeNode.SelectSingleNode(string.Format("./*[local-name() = 'binding'][@name = '{0}']", bindingName)) as XmlElement;

            if (wcfBindingConfigurationNode == null)
            {
                XmlDocument defaultBindingInfo = new XmlDocument();
                defaultBindingInfo.Load(Path.Combine(Path.Combine(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "config"), "pix"), "NotificationBinding.xml"));
                wcfBindingConfigurationNode = wcfBindingTypeNode.AppendChild(configurationDom.ImportNode(defaultBindingInfo.DocumentElement, true)) as XmlElement;
            }

            if (wcfBindingConfigurationNode.Attributes["name"] == null)
            {
                wcfBindingConfigurationNode.Attributes.Append(configurationDom.CreateAttribute("name"));
            }
            wcfBindingConfigurationNode.Attributes["name"].Value = bindingName;

            // Security?
            XmlElement wcfSecurityModeNode = wcfBindingConfigurationNode.SelectSingleNode("./*[local-name() = 'security']") as XmlElement;

            if (wcfSecurityModeNode == null)
            {
                wcfSecurityModeNode = wcfBindingConfigurationNode.AppendChild(configurationDom.CreateElement("security")) as XmlElement;
            }
            if (wcfSecurityModeNode.Attributes["mode"] == null)
            {
                wcfSecurityModeNode.Attributes.Append(configurationDom.CreateAttribute("mode"));
            }

            if (configInfo.Address.Scheme == "https")
            {
                wcfSecurityModeNode.RemoveAll();
                wcfSecurityModeNode.Attributes.Append(configurationDom.CreateAttribute("mode")).Value = "Transport";
                // Transport options
                var wcfTransportNode = wcfSecurityModeNode.AppendChild(configurationDom.CreateElement("transport")) as XmlElement;
                wcfTransportNode.Attributes.Append(configurationDom.CreateAttribute("clientCredentialType")).Value = configInfo.ClientCertificate != null ? "Certificate" : "None";
            }
            else
            {
                wcfSecurityModeNode.Attributes["mode"].Value = "None";
            }
        }